본문 바로가기
Coding/C,C++, Win32, MFC

[펌] VC 6.0 프로젝트에 manifest 파일을 추가 하는 방법 - 관리자 권한으로 실행되는 Exe, Dll 만들기

by 생각하는대로살자 2009. 8. 5.

출처 : 데브피아  /2007.08.21 뇌이버에 포스팅 한 글 가져옴.

---------------------------------------------------------------------------------------------

VC 6.0 프로젝트에 manifest 파일을 추가 하는 방법
 
1. manifest 파일 작성


실행 파일(exe)이 관리자 권한(requireAdministrator)으로 실행되어야 한다는 내용을 담은 manifest 파일을 manifest 파일을 embedding 시킬 실행파일의 이름이 vista_app.exe 라면 manifest 파일 이름을 vista_app.exe.manifest 로 하여 소스 파일이 위치한 폴더에 저장한다.

 - asm.v3
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="AdminApp"
     type="win32"/>
  <description>Description of your application</description>
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly> 

- asm.v2
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86" name="AdminApp" type="win32"/>
  <description>Description of your application</description>
  <!-- Identify the application security requirements. -->
  <ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
    <ms_asmv2:security>
      <ms_asmv2:requestedPrivileges>
        <ms_asmv2:requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </ms_asmv2:requestedPrivileges>
       </ms_asmv2:security>
  </ms_asmv2:trustInfo>
</assembly>

 - requestedPrivileges의 level 종류    

 Level     Description
 as Invoker  이 항목을 생성한 상위 프로세스의 프로세스 토큰을 상속
 highest Available  사용자가 연결된 토큰을 가진 경우 더 높은 권한의 토큰으로 응용 프로그램을 실행해야 함을 나타냅니다.일반적으로 Users 및 Administrators 그룹용으로 디자인된 UI가 있는 응용 프로그램에서 사용되며 응용 프로그램이 사용자의 전체 권한을 획득하도록 보장합니다. 유의할 점은 Backup Operators 및 Network Operators 그룹의 사용자가 연결된 토큰을 갖고, 자격 증명을 입력하도록 요구하는 프롬프트가 표시되고, 자격 증명 대화상자가 해당 사용자 타일과 Administrators 그룹의 멤버의 타일을 갖게 된다는 것 
 requireAdministrator  관리자 그룹의 멤버인 사용자 토큰에 의해 프로세스가 생성되어야 함을 정의함
   
 


 
   
2. project에 manifest 파일 추가


  1) Ctrl-R을 눌러 리소스 추가 대화상자를 연다.
  2) 저장된 vista_app.exe.manifest 파일을 import 시킨다. resource type은 RT_MANIFEST로 지정한다.
  3) project_name.rc 파일을 열어 아래의 내용을 찾아서 추가한다.
 
     -RT_MANIFEST로 전체 검색을 하면 .rc 파일을 edit 모드로 접근 할 수 있다. 

#define IDR_RT_MANIFEST1     1
#define RT_MANIFEST      24
IDR_RT_MANIFEST1 RT_MANIFEST DISCARDABLE PURE "elevate2.exe.manifest"

여담으로 맨 아랫줄의 키워드들중 DISCARDABLE, PURE가 보일것이다. 이 키워드들에 대한 설명은 MSDN의 내용으로 대체한다. 결론부터 말하자면 IDR_RT_MANIFEST1 RT_MANIFEST "elevate2.exe.manifest" 이렇게만 사용해도 상관없다.

 

MemoryFlags Specifies a set of attribute flags that can describe the state of the resource. Modifiers in the .RC script file assign these attributes to the resource. The script identifiers can assign the following flag values. Applications do not use any of these attributes. The attributes are permitted in the script for backward compatibility with existing scripts, but they are ignored. Resources are loaded when the corresponding module is loaded, and are freed when the module is unloaded.
 

 
MOVEABLE 0x0010
FIXED ~MOVEABLE
PURE 0x0020
IMPURE ~PURE
PRELOAD 0x0040
LOADONCALL ~PRELOAD
DISCARDABLE 0x1000

 

 

resource.h 에서도 IDR_RT_MANIFEST1가 정의되어 있기 때문에 재정의 컴파일 오류가 날 것이다. resource ID를 1로 변경하고 한 곳에서만 define하도록 수정해준다.

 3. 테스트
  1) 비스타에서 manifest 처리한 실행파일에 관리자 권한 요구 실행파일임을 나타내는 쉴드 마크를 확인
  2) 실행시 UAC Content 대화상자가 뜨는것을 확인

mt.exe 유틸리티를 이용한 방법
 - mt.exe는 Platform SDK를 설치하면 설치된다.
     \Program Files\Microsoft Platform SDK\Bin\mt.exe
 - VS 2005를 설치하더라도 설치된다. 
    \Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin\mt.exe
 

  1. VC 6.0 방법의 1)과 동일 
  2. VS 2005의 mt.exe를 이용해 실행 파일에 manifest 정보 추가
      - Exe
          mt -manifest vista_app.exe.manifest -outputresource:vista_app.exe;# 1
      - Dll 
          mt -manifest vista_app.dll.manifest -outputresource:vista_app.dll;# 2
3. 테스트
   VC 6.0 방법의 3)과 동일