To allow compiled programs to automatically request administrator permissions in Vista

Source: Internet
Author: User
For details about how to dynamically request permissions, refer to my other article Article (Check whether the program has admin permission and application permission Switch Under UAC of Vista)

Previously written ifeo image hijacking relief Program . However, because of the relationship in Vista, you need to set up to run with the Administrator permission. I still don't feel anything when I play it myself. Recently, my classmates asked me why I didn't succeed because I didn't set the administrator privilege. So how can a program directly request administrator permissions without user intervention? The secret is in the manifest file.
I have found some materials from the Heller's blog, but they are only e-files. If you are interested, you can read them through this article, which will be very helpful. The address is: Http://blogs.msdn.com/cheller/archive/2006/08/24/how-to-embed-a-manifest-in-an-assembly-let-me-count-the-ways.aspx
If you cannot understand it, view my analysis.
According to Heller, there are three feasible methods. The first is in. RC ( Resource script file ) File write Code The second is to merge the manifest and exe files with Mt. EXE (search for it under the Visual Studio directory); the third is to directly set the file with Visual Studio.
The first method was seen when I looked at the core programming of the system, and the Heller wrote a lot, so I was scared away. Next we can see that the third method seems to be simple, so we will try it. After looking for a long time, we won't find where to find it. Later, another foreign friend gave me a picture and found that the option was missing after my Visual Studio installed the Vista compatibility patch ==|. However, you can only select the second type.
First, we searched for the Viusal studioinstallation directory and found three mt.exe files (this is used when compiling the program ). One is. net, the other is VC, and the last is common (I guess it should be general purpose. If you are not sure, use this. I guess general purpose is generally not good ).
Next we will put the program and Mt. EXE is placed in a directory (which is purely convenient and can be left empty). The next step is to create a manifest file, which stores the following code in a text file and stores it as a file suffixed with manifest. I save it as ifeohijack.exe. manifest. The Code is as follows (here, strings such as my application can be changed to your favorite program information ): <? XML version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
< Assembly Xmlns = "Urn: Schemas-Microsoft-com: ASM. V1" Manifestversion = "1.0" >
< Assemblyidentity
Processorarchitecture = "X86"
Version = "5.1.0.0"
Type = "Win32"
Name = "Myapplication"
/>
< Description > My application </ Description >
< Dependency >
< Dependentassembly >
< Assemblyidentity
Type = "Win32"
Name = "Microsoft. Windows. Common-Controls"
Version = "6.0.0.0"
Publickeytoken = "6595b64144ccf1df"
Language = "*"
Processorarchitecture = "X86"
/>
</ Dependentassembly >
</ Dependency >
< Trustinfo Xmlns = "Urn: Schemas-Microsoft-com: ASM. V3" >
< Security >
< Requestedprivileges >
< Requestedexecutionlevel Level = "Requireadministrator" UIAccess = "False" />
</ Requestedprivileges >
</ Security >
</ Trustinfo >
</ Assembly >

After saving it, we will start work. Open the command prompt, locate the directory to Mt. EXE, and then run the following command:

Mt.exe-manifest exename.exe. manifest-outputresource: exename.exe; #1

As shown in:

In, I changed the mt.exeused In the. NET program to mt_net.exe.
Finally, we can delete the manifest file. After the modified program is put into the Vista system, the Administrator will be automatically requested ~

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.