I'm using Delphi XE4 and I have no idea how to make an application ask administrative permission to Windows 7 to run, I looked at websites and bolgs, but I did not find the answer! Help me please!
I'm using Delphi XE4 and I have no idea how to make an application ask administrative permission to Windows 7 to run, I looked at websites and bolgs, but I did not find the answer! Help me please!
First you should create a text file with the following content:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="Teste" version="3.1.0.0" processorArchitecture="*"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" publicKeyToken="6595b64144ccf1df" language="*" processorArchitecture="*"/>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates application support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates application support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--Windows 8 Support -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
</application>
</compatibility>
</assembly>
Save as "Manifest.manifest" inside the folder of your project (I recommend that you create a subfolder called "Resources" to place these files).
Then create another text file with the following content:
1 24 "Manifest.manifest"
Save this other file named Manifest.rc, in the same folder where you saved the "Manifest.manifest" file above.
Then after that compile this file using the following command line (or create a BAT for this):
BRCC32.exe Manifest.rc
A file called Manifest.res will be automatically created
Then, finally, add the following line in your code:
{$R 'Manifest.res'}
In this way, when you open the executable, if Windows UAC is enabled, you will be required to elevate the privileges.
I hope I have helped! Good luck!
To do this you will need to create a custom Manifest file.
Tip: To learn more about custom Manifest file you can give a look at this Embarcadero link : Customizing the Windows Application Manifest File
YOU CAN USE THIS FILE HERE
If you prefer you can use this ready, just do the following:
Content of the manifest file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="Teste" version="3.1.0.0" processorArchitecture="*"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" publicKeyToken="6595b64144ccf1df" language="*" processorArchitecture="*"/>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates application support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates application support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--Windows 8 Support -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
</application>
</compatibility>
</assembly>
USING MANIFEST ON YOUR PROJECT
Follow the steps below:
With Manifest you should notice that pressing F9 to run your application in debug mode Delphi will not be able to run your application, the solution is to close the Delphi IDE and open it again with the Run as administrator
IMAGES THAT ILLUSTRATE THE STEPS I INDICATED
Steps 1 to 4
Step5
Step6
I've added windows versions in XML if someone needs to:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="NOME DO APLICATIVO COM A EXTESÃO (.EXE)" version="3.1.0.0" processorArchitecture="*"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" publicKeyToken="6595b64144ccf1df" language="*" processorArchitecture="*"/>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--Windows Vista/6.0/Server 2008-->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--Windows 7/6.1/Server 2008 R2-->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--Windows 8/6.2/Server 2012-->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!--Windows 8.1/6.3/Server 2012 R2-->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!--Windows 10/10.*-->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>