2014년 10월 29일 수요일

mfc 실행프로그램 관리자권한 실행하는 manifest. mt.exe 이용

여러 사이트에 관리자권한으로 실행해주는 manifest가 존재하지만 실제로 적용해보면 이상하게 동작한다.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <description></description>
  <!-- Identify the application security requirements (Vista): -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
    </security>
  </trustInfo>
  <!-- Activate Windows Common Controls v6 usage (XP and Vista): -->
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>
</assembly>

위는 내가 쓰는 manifest인데 아래 부분의 common-controls 이 부분이 없으면 윈도우 컨트롤러들의 ui가 이상해진다.

예를 들어, edit control의 password 속성을 주면 윈7에서는 ● 이런 표시로 되지만, 예전 윈도우에서는(윈도우98이나 윈도우2000인 것 같다)*** 별표로 표시가 됐다.

common-controls 부분이 없으면 **** 이런식으로 표시가 된다. 이거 찾느라 몇 시간을 고생했는지...

edit control 말고도 list control, combo box  등등 ui가 구식으로 바뀐다.


 UAC.manifest

그리고 일반적으로 구글링 해보면 mt.exe를 다음과 같이 사용한다.

mt.exe -manifest ExeName.exe.manifest -outputresource:”ExeName.exe”;#1

manifest파일의 이름과 실행파일의 이름을 같게 해서...

근데 굳이 이렇게 할 필요는 없다. 그리고 manifest파일의 xml의 attribute에 파일 이름을 줄 수 있는데 이것 또한 할 필요 없다.

그냥 링크 걸어놓은 manifest파일을 받아서 다음과 같이 하면 된다.

mt.exe -manifest UAC.manifest -outputresource:"MyExe.exe";#1

굳이 막 파일 별로 여러 개의 manifest파일을 만들 필요가 없다는 것이다.

Visual studio에서 빌드 후 이벤트에 설정할 때는 다음과 같이 하면 된다.

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\mt.exe" -manifest 블라블라

visual studio 2010의 경우 mt.exe가 다른 곳에 또 있던데, 우리가 찾는 mt.exe의 위치는 위의 경로가 맞다.

댓글 없음: