change exe option to run as administrator by bat script on Windows 7

3

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.

user730794

Posted 2011-11-22T12:57:44.973

Reputation:

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 – 2011-11-22T13:36:25.113

1Do 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 – 2011-11-23T05:14:39.620

Answers

5

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.

Hand-E-Food

Posted 2011-11-22T12:57:44.973

Reputation: 4 711

1

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: http://www.winability.com/elevate/

socha23

Posted 2011-11-22T12:57:44.973

Reputation: 111

0

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.

@ECHO OFF
::Ask for admin access
if exist "admincheckOK.txt" goto adminOK1
del /Q admincheckOK.vbs
ECHO.
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. oShell.run "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
:adminOK1
del /Q admincheckOK.txt
del /Q admincheckOK.vbs

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

REM Following statement required if Admin access denied
:theend
del /Q admincheckOK.vbs

surfasb

Posted 2011-11-22T12:57:44.973

Reputation: 21 453

0

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="1.0.0.0"
            processorArchitecture="X86"
            name="appname"
            type="win32"/> 
<description>elevate execution level</description> 
   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
      <security>
         <requestedPrivileges>
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
         </requestedPrivileges>
      </security>
   </trustInfo>
</assembly>

(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.

Kate Gregory

Posted 2011-11-22T12:57:44.973

Reputation: 966