Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can't disable UAC in Windows 7 and I want to change .exe option to run as administrator. I can right click on icon and goto compatibility then change this option through GUI but I have to do by .bat..... Can someone give me a demo .bat.

share|improve this question

migrated from Nov 23 '11 at 5:11

This question came from our site for professional and enthusiast programmers.

I don't believe such a possibility is even supposed to be there in Windows 7. Elevating rights programmatically is something that Windows XP allows you to do and a thing that can potentially be (and probably is) exploited by malware. If Windows 7's UAC allowed elevating rights programmatically without user's consent, that would seem to me like stepping on the same rake. – Andriy M Nov 22 '11 at 13:36
Do you just want to launch something from a batch script as admin. Or do you want to change the exe to always run as admin (like you can in the compatibility tab)? – Dracs Nov 23 '11 at 5:14

Right-click the BAT file and press Create Shortcut. The shortcut will appear. You can edit the shortcut's properties and set it to always run as administrator. Of course, you have to run the BAT file through the shortcut now.

share|improve this answer

I don't think it's possible in plain windows without installing an additional utility to elevate priviledges from the command line.

If you accept bundling such an utility with your bat file (or installing it system-wide), check this out:

share|improve this answer

Another method is to have the batchfile call a VBscript that then elevates the batchfile.

You can download the Elevate PowerToys which allow you to elevate batchfiles.

elevate -batchfile-

Another method is to create a self elevating script. This can be a fragile method but it basically assumes you have write access to the %temp%

It's a modified version of the one here.

::Ask for admin access
if exist "admincheckOK.txt" goto adminOK1
del /Q admincheckOK.vbs
ECHO. Please wait...
echo.Set objShell = CreateObject("Shell.Application") > %TEMP%\admincheckOK.vbs
echo.Set FSO = CreateObject("Scripting.FileSystemObject") >> %TEMP%\admincheckOK.vbs
echo.strPath = FSO.GetParentFolderName (WScript.ScriptFullName) >> %TEMP%\admincheckOK.vbs
echo.If FSO.FileExists(%0) Then >> %temp%\admincheckOK.vbs
echo. Dim oShell >> %TEMP%\admincheckOK.vbs
echo. Set oShell = WScript.CreateObject ("WScript.Shell") >> %TEMP%\admincheckOK.vbs
echo. "cmd.exe /c echo admincheckOK > admincheckOK.txt" >> %TEMP%\admincheckOK.vbs
echo. Set oShell = Nothing >> %TEMP%\admincheckOK.vbs
echo. objShell.ShellExecute "cmd.exe", " /c " ^& %0 ^& " ", "", "runas", 1 >> %TEMP%\admincheckOK.vbs
echo.Else >> %TEMP%\admincheckOK.vbs
echo. MsgBox "Script file not found" >> %TEMP%\admincheckOK.vbs
echo.End If >> %TEMP%\admincheckOK.vbs
cscript //B %TEMP%\admincheckOK.vbs
goto theend

::Admin Access allowed
del /Q admincheckOK.txt
del /Q admincheckOK.vbs

::**Body of Batchfile**
::**Code you want elevated**

REM Following statement required if Admin access denied
del /Q admincheckOK.vbs
share|improve this answer

For an exe, if you put a manifest in the same folder as the exe that requests elevation, every time anyone runs the app they will be prompted to elevate it. Deleting the file from the folder will put the behaviour back to normal.

The name of the file must be exename.exe.manifest, in other words if you have foo.exe then you must name the file foo.exe.manifest. The contents must look like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
    <assemblyIdentity version=""
<description>elevate execution level</description> 
   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>

(The name and description don't matter, feel free to make them match your app. Or not.)

This will not work if the exe has an embedded manifest requesting a lower execution level, but will work for an manifest-less application.

I'm not sure why you want to turn this on and off with a batch file, but you can easily do it by having your batch file rename this file to foo.exe.notmanifest and back to foo.exe.manifest.

share|improve this answer

You must log in to answer this question.