VS2005 works under Win7 Run with Administrator privileges

Source: Internet
Author: User

want to close the informationhttp://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 (source)Method 1VISTA/WIN7 uses UAC to enforce rights management, and some programs require users to indicate administrator privileges to function properly. So how do you make a program run as an administrator by default? The answer is manifest.

The steps are as follows:

1. Create a new file in the project, such as Mani.xml.
Its content is

< 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>

The Blue line is the key. The default is Asinvoker. This is changed to Requireadministrator.
2. Right-click the project and select Properties. In the Mainfest tool section, select Input and Output, and in additional Manifest files, enter the XML file you just created.
3. Rebuild, there may be a warning(81010002), regardless: (note, in order to get the detailed information, I set the project properties-Manifest tool-general in the suppress Startup Banner to No, Verbose Output set to 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:schem As-microsoft-com:asm.v3 ".
1>build log is 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 ==========

You can then see that the icon for the generated EXE has changed, with a small shield on it:


Double-click Run, pop up the UAC confirmation box, OK.

Finally, the warning above: the VC2005 manifest tool Mt.exe is 5.2.3790.2025, updated to 6.1.7716.0 in the Windows SDK, and the warning disappears.

Kudouman Supplement:

MT in Visual Studio 2005. EXE is having problems loading UAC MANIFEST,
Causes Windows XP SP2 to crash SXS.DLL and a blue screen of Windows.
1. Replace the Mt.exe in Visual Studio 2005 RTM with the Mt.exe inside the Microsoft Windows Vista SDK
2. Using Visual Studio 2005 SP1
I don't know who installed the VS 2005 SP1 or VISTA SDK to share MT. EXE? Thank you
If you downloaded Microsoft Windows Vista SDK from Microsoft, install it later in C:\Program Files\Microsoft Sdks\windows\v6.0\bin\mt.exe get the file.
If it's a VS 2005 SP1, in C:\Program Files\Microsoft Visual Studio 8\vc\bin\mt.exe

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.