0

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

xhah730
  • 13
  • 4

2 Answers2

1

Create the batch file, then right click it in Windows Explorer. Go to the Compatibility tab and click "Run this program as an administrator"

Chris E
  • 973
  • 13
  • 26
  • which i want is when someone double click on file it opens in administrator mode..... whether it is in my own pc or someone pc – xhah730 Dec 01 '11 at 17:25
  • That really can't be done and you don't want to anyway. Think about it. You're asking how to make a batch file automatically have administrator access on whatever machine it's copied to. The harm potential is astronomical. How would you like to copy a file to your computer and have it automatically (and without your consent) gain full control of your PC? – Chris E Dec 01 '11 at 19:53
0

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