성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>TrustedInstaller 권한으로 프로그램 실행시키는 방법</h1> <p> TrustedInstaller 사용자 권한으로 문제되는 경우들이 종종 있죠.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > SYSTEM 또는 TrustedInstaller 소유로 되어 있는 폴더/파일을 삭제하는 방법 ; <a target='tab' href='http://www.sysnet.pe.kr/2/0/1519'>http://www.sysnet.pe.kr/2/0/1519</a> </pre> <br /> 속성 창의 보안 탭을 통해 조정하는 것도 한두번이지, 반복되다 보면 이제 슬슬 ^^ '중복 제거'의 필요성이 느껴집니다. 가장 좋은 방법은 자동화를 위해 TrustedInstaller 권한으로 프로그램을 실행시킬 수 있는 것인데, 검색해 보면 다음의 도구가 나옵니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > New version of DevxExec ? run a process from different user credentials ; <a target='tab' href='http://developex.com/blog/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/</a> Run process from different credentials? Simple with DevxExec.exe! ; <a target='tab' href='http://developex.com/custom-software/devx-exec.html'>http://developex.com/custom-software/devx-exec.html</a> </pre> <br /> devxexec를 이용하면 이렇게 쉽게 TrustedInstaller 권한으로 프로그램을 실행할 수 있다고 합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > devxexec.exe /user:TrustedInstaller cmd </pre> <br /> 하지만, 아쉽게도 Windows 8.1을 지원하지 않는 관계로 테스트 해볼 수 없었습니다. (Windows 7에서는 된다고 합니다.)<br /> <br /> 그다음 검색된 방법이 바로 이것입니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Doing Stuff While Impersonating Trusted Installer Which is technically the same thing as Running Programs as NT System Authority in Vista, 7, etc ; <a target='tab' href='http://vorck.com/windows/ntauth.html'>http://vorck.com/windows/ntauth.html</a> RunasSystem and RunFromToken ; <a target='tab' href='http://reboot.pro/topic/17501-runassystem-and-runfromtoken/'>http://reboot.pro/topic/17501-runassystem-and-runfromtoken/</a> </pre> <br /> 이 유틸리티는 다음의 경로에서 다운로드 받을 수 있고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > RunasSystem and RunFromToken ; <a target='tab' href='http://reboot.pro/files/file/237-runassystem-and-runfromtoken/'>http://reboot.pro/files/file/237-runassystem-and-runfromtoken/</a> </pre> <br /> RunasSystem_v1.0.0.3.zip 파일과 RunFromToken_v1.0.0.2.zip 파일의 압축을 풀어 하나의 폴더에 합쳐, 이렇게 실행해 주면 됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > RunasSystem64 "RunFromToken64 trustedinstaller.exe 1 cmd" </pre> <br /> 의미는 이렇습니다. RunasSystem64 프로그램은 전달받은 인자의 내용을 SYSTEM 권한으로 실행해 줍니다. 그리하여 SYSTEM 권한하에서 실행된 RunFromToken64 프로그램은 인자로 받은 trustedinstaller.exe 프로세스의 보안 토큰을 복제해 1번 세션에서 cmd.exe 프로세스를 실행해 줍니다. 결과적으로 새롭게 실행된 cmd.exe는 TrustedInstaller 사용자 권한으로 실행되는 것입니다.<br /> <br /> 직접 한번 해봤는데요. 윈도우 8.1에서 "관리자 권한으로 cmd.exe"를 실행시키고 명령행에서 실행했는데, 처음 한번은 다음과 같이 실행되었습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 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 <span style='color: blue; font-weight: bold'>Reboot required for changes to take effect</span> Now setting privilege: SeIncreaseQuotaPrivilege Running in session: 1 Host PID: 936 </pre> <br /> 부팅이 필요하다고 하는군요. ^^ 어쨌든 부팅 후에 재실행했을 때는 정상적으로 새로운 cmd.exe 창이 떴습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 참고로, RunFromToken64.exe 프로그램은 현재 실행 중인 프로세스의 보안 토큰을 복제하기 때문에 반드시 인자로 지정된 프로그램이 실행 중이어야 합니다. 문제는, trustedinstaller.exe 프로세스가 '프로그램 설치' 작업 시에만 자동 실행되고 평소에는 중지되기 때문에 보통은 실행이 안되어 있습니다. 따라서, 일부러 trustedinstaller.exe 프로세스를 실행해 주어야 하는데 NT 서비스이기 때문에 다음과 같은 명령행으로 실행시켜 줄 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > net start trustedinstaller </pre> <br /> <hr style='width: 50%' /><br /> <br /> 처음에 저는, trustedinstaller 서비스(Windows Modules Installer)가 프로그램 설치에 관여하기 때문에 제가 임의로 설치 프로그램을 만들어 실행하면 그 사이의 코드는 trustedinstaller 권한으로 실행될 거라고 생각했습니다.<br /> <br /> 테스트를 위해 Visual Studio 2013의 설치 프로젝트를 활성화하고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Microsoft Visual Studio 2013 Installer Projects ; <a target='tab' href='https://marketplace.visualstudio.com/items?itemName=UnniRavindranathan-MSFT.MicrosoftVisualStudio2013InstallerProjects'>https://marketplace.visualstudio.com/items?itemName=UnniRavindranathan-MSFT.MicrosoftVisualStudio2013InstallerProjects</a> </pre> <br /> "Custom Action"을 통해,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Walkthrough: Creating a Custom Action ; <a target='tab' href='https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/d9k65z2d(v=vs.100)'>https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/d9k65z2d(v=vs.100)</a> </pre> <br /> 설치 작업 중에 제가 원하는 동작을 할 수 있도록 코드를 심었습니다. <br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 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); } } } </pre> <br /> 그런데 실제로 테스트 해보면, trustedinstaller 사용자 권한이 아닌, "Local SYSTEM" 사용자 권한으로 실행되었습니다. 아쉽군요. ^^<br /> <br /> (어쨌든, 이 방법을 통하면 프로그램을 "Local SYSTEM" 권한으로 <a target='tab' href='http://www.sysnet.pe.kr/2/0/1584'>psexec.exe</a>를 통하지 않고도 실행할 수 있게 됩니다.)<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1891
(왼쪽의 숫자를 입력해야 합니다.)