Run exe under Vista or Win7 as Administrator -- C # and Delphi Solution

Source: Internet
Author: User

Address: http://clacklin.blog.163.com/blog/static/103209820106108538269/

Open the Vs2005 or vs2008 project and check whether the app. manifest file exists in Properties. If not, right-click the project and choose "Properties" from the menu ",

Select "security" and select "enable ClickOnce Security Settings" on the interface. The app. manifest file is automatically generated under Properties.

Open the app. manifest file and add
<RequestedPrivileges>
<RequestedExecutionLevel level = "requireAdministrator" cess = "false"/>
</RequestedPrivileges>, recompile,
The Code is as follows:
<Xml version = "1.0" encoding = "UTF-8">
<Asmv1: assembly manifestVersion = "1.0" xmlns = "urn: schemas-microsoft-com: asm. v1 "xmlns: asmv1 =" urn: schemas-microsoft-com: asm. v1 "xmlns: asmv2 =" urn: schemas-microsoft-com: asm. v2 "xmlns: xsi =" http://www.w3.org/2001/XMLSchema-instance ">
<TrustInfo xmlns = "urn: schemas-microsoft-com: asm. v2">
<Security>
<ApplicationRequestMinimum>
<PermissionSet class = "System. Security. PermissionSet" version = "1" Unrestricted = "true" ID = "Custom" SameSite = "site"/>
<DefaultAssemblyRequest permissionSetReference = "Custom"/>
</ApplicationRequestMinimum>
<RequestedPrivileges>
<RequestedExecutionLevel level = "requireAdministrator" uiAccess = "false"/>
</RequestedPrivileges>
</Security>
</TrustInfo>
</Asmv1: assembly>

2) Delphi: the Delphi program must embed MANIFEST information in the resource.
Edit an object as follows:
<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"/>
</RequestedPrivileges>
</Security>
</TrustInfo>
</Assembly>

Save as UAC. manifest. The file is random here. Pay special attention to the red "requireAdministrator", which indicates that the program must run properly as Administrator.
Edit an RC file named uac. rc as follows:

1 24 UAC. manifest
Where:
1-resource ID
24-the resource type is RTMAINIFEST
UAC. manifest-previous file name
Use brcc32 to compile this rc file as the res file, as shown below:
Brcc32 uac. rc-fouac. res
Add in the program
{$ R uac. res}
Compile uac. res into the exe file during Delphi compilation.
Put the file in vista or win7 and run it. The UAC shield icon is displayed under the program icon.

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.