Automatically upgrade the process permissions on Vista and win7-rt_manifest

Source: Internet
Author: User
Tags superuser permission


Many times, applications developed by myself need to run with higher user permissions, especially under Vista and win7.

How to make your own applications run in the same way as below, prompting for permission improvement.

 

 

Method:

1. compile and generate the. exe file by using the C program;

2. Create a new file named "cmd.exe +. manifest" under the debugor releasefolder. If your application name is myapp.exe, create a file named myapp.exe. manifest in the directory of myapp.exe.pdf and open the file in text format (such as NotePad)

3.paste the following xmlfield to the newly created myapp.exe. manifest file and save it.

<? XML version = '1. 0' encoding = 'utf-8' standalone = 'Yes'?>
<Assembly xmlns = 'urn: Schemas-Microsoft-com: ASM. V1 'manifestversion = '1. 0'>
 <Trustinfo xmlns = "urn: Schemas-Microsoft-com: ASM. V3">
   <Security>
     <Requestedprivileges>
       <Requestedexecutionlevel level = 'requireadministrator 'UIAccess = 'false'/>
     </Requestedprivileges>
   </Security>
 </Trustinfo>
</Assembly>

 

The "level" attribute in the requestedexecutionlevel element can be taken down from the following values (simple English, I believe everyone can understand ):

 

4. Run the. NET visual studiocommand prompt (the tool named "cmd.exe" under .net, not in the windowsattachment ). If you have installed Visual Studio. NET 2003, 2005, 2008, 2010, and other development tools, you can find them under the Start Menu-> Visual Studio 2003 or 2005-> Visual Studio tool.

5. After running the. NET visual studiocommand prompt, change the current directory to the directory where your application (myapp.exe) is located, and enter the following command:

Mt.exe-manifest "myapp.exe. manifest"-outputresource: "myapp.exe"; #1 

(Replace MyApp with your own application name)

6. Then you can see it in the app's directory. Now, the app's icon has an additional security shield.

A prompt is displayed when you run the program.

 

Note: If you are developing a dynamic link library DLL. The command entered at the. NET Visual Studio command prompt should be:

Mt.exe-manifest "MyApp. dll. manifest"-outputresource: "MyApp. dll"; #2.

 

 

Finally, you may want to test the method described in this article by yourself. Write a simple application to modify the system time in Vista or Windows 7. before using this method, check whether the modification is successful. If you cannot try the method described in this article, run the program and check whether the modification is successful.

The code for modifying the system time is as follows:

 Coledatetime TM;
 Systemtime st;
 TM. parsedatetime (_ T ("2000-10-10 17:00:00 "));
 TM. getassystemtime (ST );
 Setlocaltime (& St );



_______________________________


Enhance the application execution permission under Vista


The superuser permission is not used by default when the Vista system application is executed. This will cause some IO operations that fail to create files and directories and cause access errors. This phenomenon is caused by the UAC feature of Vista.

To avoid this situation, you can force the user to execute the program with the superuser permission when running the application. Specific Practices:

1. Edit the manifest file. Configure the parameters and execution environment required for application execution in the manifest file. The following is an example:

 

<?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="IsUserAdmin"
     type="win32"/> 
     
  <description>Description of your application</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>

 </assembly>


2. Edit the resource file of the application (file with the RC suffix) and add the following two lines of code to it:


#define MANIFEST_RESOURCE_ID 1
MANIFEST_RESOURCE_ID RT_MANIFEST "{Application.exe}.manifest"


Replace application.exe with the executable file name to be compiled.

3. Compile the link program to generate executable applications.

4. Run the mt.exe command to link the manifest file with the generated executable program. Write the manifest content to the executable file.
Command Behavior:


Mt.exe-manifest temp. manifest-outputresource: yourapp.exe; #1


In this step, the UAC confirmation box will pop up when the generated executable file is running under Vista, asking the user to confirm and execute the application with the superuser permission.

Refer:
1. http://msdn.microsoft.com/en-us/library/bb756973.aspx
Designing UAC applications for Windows Vista

2. http://msdn.microsoft.com/en-us/library/bb756996.aspx
AC: User Account Control

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.