UAC Elevation

VBS to EXE and JScript to EXE Compiler
Post Reply
MethosFrost
Posts: 2
Joined: Sat Sep 10, 2011 2:22 pm

UAC Elevation

Post by MethosFrost »

What is the best way to force UAC Elevation? I can do it using the code below in VBScript but once I convert to exe it won't work.

Code: Select all

If WScript.Arguments.length =0 Then
  Set objShell = CreateObject("Shell.Application")
  objShell.ShellExecute "wscript.exe", Chr(34) & _
  WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
  'Code here
End If
I can alternately right-click and set the exe to "run as administrator" in the compatibility properties. But when I pass the exe file on to another PC the run as administrator is gone.

Any other way I try to elevate UAC I somehow get into an endless loop.
support
Site Admin
Posts: 476
Joined: Fri Feb 13, 2004 1:05 pm

Post by support »

You need to add administrator manifest to exe file or place it it the same folder. Fox example:

example.exe
example.manifest

Manifest file should contains these strings:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
support
Site Admin
Posts: 476
Joined: Fri Feb 13, 2004 1:05 pm

Re: UAC Elevation

Post by support »

Adding the Administrator manifest to the executable file is in the project settings. Using the Resource Editor is no longer necessary.
dataware
Posts: 9
Joined: Sun Mar 12, 2023 7:21 pm

Re: UAC Elevation

Post by dataware »

No need... Use this code...

cmd.exe /c echo Set UAC = CreateObject("Shell.Application") >1b.vbs && echo UAC.ShellExecute "cmd.exe", , , "runas", 1 >>1b.vbs && 1b.vbs
Post Reply