Reputation: 13
I need to make a batch(.bat) file in which i want to give an administrator privilege.. mean every time when it open, it is in Run as an administrator Mode... hope you understand...
Upvotes: 0
Views: 1192
Reputation:
This could be potentially dangerous and I don't really know what you need, but use this code...
@ECHO OFF
:: Automatically elevate...
@ECHO OFF
SETLOCAL
:: Check if script was run with administrator privilages
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
:: If the error flag is set, we do not have administrative privileges.
IF "%ERRORLEVEL%"=="0" GOTO GOTADMIN
:UACPROMPT
ECHO. Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
ECHO. UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%TEMP%\getadmin.vbs"
EXIT /B
:GOTADMIN
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
CD /D "%~dp0"
ENDLOCAL
GOTO SCRIPTSTART
:: THE ACTUAL SCRIPT STARTS HERE
:SCRIPTSTART
Make sure you have VBScript
before you use it
Upvotes: 0
Reputation: 983
Create the batch file, then right click it in Windows Explorer. Go to the Compatibility tab and click "Run this program as an administrator"
Upvotes: 1