TrustedInstaller 권한으로 프로그램 실행시키는 방법
TrustedInstaller 사용자 권한으로 문제되는 경우들이 종종 있죠.
SYSTEM 또는 TrustedInstaller 소유로 되어 있는 폴더/파일을 삭제하는 방법
; https://www.sysnet.pe.kr/2/0/1519
속성 창의 보안 탭을 통해 조정하는 것도 한두번이지, 반복되다 보면 이제 슬슬 ^^ '중복 제거'의 필요성이 느껴집니다. 가장 좋은 방법은 자동화를 위해 TrustedInstaller 권한으로 프로그램을 실행시킬 수 있는 것인데, 검색해 보면 다음의 도구가 나옵니다.
New version of DevxExec ? run a process from different user credentials
; http://developex.com/blog/new-version-of-devxexec-run-a-process-from-different-user-credentials/
Run process from different credentials? Simple with DevxExec.exe!
; http://developex.com/custom-software/devx-exec.html
devxexec를 이용하면 이렇게 쉽게 TrustedInstaller 권한으로 프로그램을 실행할 수 있다고 합니다.
devxexec.exe /user:TrustedInstaller cmd
하지만, 아쉽게도 Windows 8.1을 지원하지 않는 관계로 테스트 해볼 수 없었습니다. (Windows 7에서는 된다고 합니다.)
그다음 검색된 방법이 바로 이것입니다.
Doing Stuff While Impersonating Trusted Installer Which is technically the same thing as Running Programs as NT System Authority in Vista, 7, etc
; http://vorck.com/windows/ntauth.html
RunasSystem and RunFromToken
; http://reboot.pro/topic/17501-runassystem-and-runfromtoken/
이 유틸리티는 다음의 경로에서 다운로드 받을 수 있고,
RunasSystem and RunFromToken
; http://reboot.pro/files/file/237-runassystem-and-runfromtoken/
RunasSystem_v1.0.0.3.zip 파일과 RunFromToken_v1.0.0.2.zip 파일의 압축을 풀어 하나의 폴더에 합쳐, 이렇게 실행해 주면 됩니다.
RunasSystem64 "RunFromToken64 trustedinstaller.exe 1 cmd"
의미는 이렇습니다. RunasSystem64 프로그램은 전달받은 인자의 내용을 SYSTEM 권한으로 실행해 줍니다. 그리하여 SYSTEM 권한하에서 실행된 RunFromToken64 프로그램은 인자로 받은 trustedinstaller.exe 프로세스의 보안 토큰을 복제해 1번 세션에서 cmd.exe 프로세스를 실행해 줍니다. 결과적으로 새롭게 실행된 cmd.exe는 TrustedInstaller 사용자 권한으로 실행되는 것입니다.
직접 한번 해봤는데요. 윈도우 8.1에서 "관리자 권한으로 cmd.exe"를 실행시키고 명령행에서 실행했는데, 처음 한번은 다음과 같이 실행되었습니다.
C:\RunasSystem_v1.0.0.3>RunasSystem64 "RunFromToken64 trustedinstaller.exe 1 cmd"
Now setting privilege: SeDebugPrivilege
Now setting privilege: SeAssignPrimaryTokenPrivilege
AdjustTokenPrivileges (SeAssignPrimaryTokenPrivilege): Not all privileges or groups referenced are assigned to the caller.
LsaAddAccountRights 0x00000000
Reboot required for changes to take effect
Now setting privilege: SeIncreaseQuotaPrivilege
Running in session: 1
Host PID: 936
부팅이 필요하다고 하는군요. ^^ 어쨌든 부팅 후에 재실행했을 때는 정상적으로 새로운 cmd.exe 창이 떴습니다.
참고로, RunFromToken64.exe 프로그램은 현재 실행 중인 프로세스의 보안 토큰을 복제하기 때문에 반드시 인자로 지정된 프로그램이 실행 중이어야 합니다. 문제는, trustedinstaller.exe 프로세스가 '프로그램 설치' 작업 시에만 자동 실행되고 평소에는 중지되기 때문에 보통은 실행이 안되어 있습니다. 따라서, 일부러 trustedinstaller.exe 프로세스를 실행해 주어야 하는데 NT 서비스이기 때문에 다음과 같은 명령행으로 실행시켜 줄 수 있습니다.
net start trustedinstaller
처음에 저는, trustedinstaller 서비스(Windows Modules Installer)가 프로그램 설치에 관여하기 때문에 제가 임의로 설치 프로그램을 만들어 실행하면 그 사이의 코드는 trustedinstaller 권한으로 실행될 거라고 생각했습니다.
테스트를 위해 Visual Studio 2013의 설치 프로젝트를 활성화하고,
Microsoft Visual Studio 2013 Installer Projects
; https://marketplace.visualstudio.com/items?itemName=UnniRavindranathan-MSFT.MicrosoftVisualStudio2013InstallerProjects
"Custom Action"을 통해,
Walkthrough: Creating a Custom Action
; https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/d9k65z2d(v=vs.100)
설치 작업 중에 제가 원하는 동작을 할 수 있도록 코드를 심었습니다.
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
namespace MsiCustomAction
{
[RunInstaller(true)]
public partial class InstallerAction : System.Configuration.Install.Installer
{
public InstallerAction()
{
InitializeComponent();
}
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
Trace.WriteLine("Custom Action - Install..." + Environment.UserName);
}
protected override void OnCommitting(IDictionary savedState)
{
base.OnCommitting(savedState);
Trace.WriteLine("Custom Action - OnCommitting..." + Environment.UserName);
}
}
}
그런데 실제로 테스트 해보면, trustedinstaller 사용자 권한이 아닌, "Local SYSTEM" 사용자 권한으로 실행되었습니다. 아쉽군요. ^^
(어쨌든, 이 방법을 통하면 프로그램을 "Local SYSTEM" 권한으로
psexec.exe를 통하지 않고도 실행할 수 있게 됩니다.)
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]