VS2005 工程在win7下使用管理員權限運行

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   tar   

想關資料http://stackoverflow.com/questions/13030492/set-administrator-privilege-for-my-c-application-in-vs2005 http://msdn.microsoft.com/en-us/library/bb756929.aspxhttp://msdn.microsoft.com/en-us/library/ms235591.aspx    //================================================= http://blog.csdn.net/jjchao/article/details/7041335(來源)  方法1Vista/Win7使用UAC加強了許可權管理,一些程式需要使用者指明管理員權限才能正常運行。那麼如何讓一個程式預設就是以管理員方式運行呢?答案是Manifest.

步驟如下:

1. 在工程中建立一個檔案,例如mani.xml。
其內容為

< ?xml version="1.0" encoding="UTF-8" standalone="yes"?>
< assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
< ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
< ms_asmv2:security>
< ms_asmv3:requestedPrivileges xmlns:ms_asmv3="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level=" requireAdministrator" uiAccess="false" />
< /ms_asmv3:requestedPrivileges>
< /ms_asmv2:security>
< /ms_asmv2:trustInfo>
< /assembly>

藍色的一行是關鍵的。預設是asInvoker。這裡改成requireAdministrator.
2. 右鍵項目,選擇Properties。在Mainfest Tool一節,選擇Input and Output,在Additional Manifest Files中,輸入剛才建立的xml檔案。
3. Rebuild,這時可能會出現一個警告(81010002),不用理會:(注,為了得到詳細的資訊,我把項目屬性 - Manifest Tool - General 中的Suppress Startup Banner 設定成No, Verbose Output 設定成Yes)
1>------ Rebuild All started: Project: test, Configuration: Release Win32 ------
1>Deleting intermediate and output files for project ‘test‘, configuration ‘Release|Win32‘
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>test.cpp
1>Linking...
1>Generating code
1>Finished generating code
1>Embedding manifest...
1>Microsoft (R) Manifest Tool version 5.2.3790.2075
1>Copyright (c) Microsoft Corporation 2005.
1>All rights reserved.
1>.\mani.xml : manifest authoring warning 81010002: Unrecognized Element "requestedPrivileges" in namespace "urn:schemas-microsoft-com:asm.v3".
1>Build log was saved at "file://f:\myworks\test\test\Release\BuildLog.htm"
1>test - 0 error(s), 1 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

然後可以看到產生的exe檔案的表徵圖變了,上面多了個小盾牌:


雙擊運行,彈出了UAC的確認框,OK了。

最後關於上面的警告:VC2005帶的Manifest工具mt.exe是5.2.3790.2025版本的,更新成Windows SDK中帶的6.1.7716.0,那個警告就消失了。

 

Kudouman補充:

Visual Studio 2005 中的 MT.EXE 在載入 UAC 的 MANIFEST 有問題, 
會導致了Windows XP SP2的SXS.DLL崩潰和Windows的藍屏。
1。 使用 Microsoft Windows Vista SDK 裡面的mt.exe替換 Visual Studio 2005 RTM 裡面的mt.exe 
2。 使用 Visual Studio 2005 SP1 
不知道哪位安裝了 VS 2005 SP1 或者 VISTA SDK 能夠分享一下 MT.EXE 嗎? 謝謝
如果是從Microsoft下載Microsoft Windows Vista SDK,安裝以後在C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\mt.exe獲得檔案。 
如果是 VS 2005 SP1 的話 , 在 C:\Program Files\Microsoft Visual Studio 8\VC\bin\mt.exe

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.