Return to Snippet

Revision: 94015
at January 20, 2024 18:14 by deanhouseholder


Updated URL

                                

Updated Language
Windows PowerShell

Revision: 66087
at March 12, 2014 10:09 by deanhouseholder


Initial Code
:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
@echo off
CLS
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================

:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
if '%1'=='ELEV' (shift & goto gotPrivileges)
ECHO.
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************

setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
"%temp%\OEgetPrivileges.vbs"
exit /B

:gotPrivileges
::::::::::::::::::::::::::::
:START
::::::::::::::::::::::::::::
setlocal & pushd .

REM Run shell as admin (example) - put here code as you like
cmd /k echo. && echo *** ADMIN CONSOLE ***

Initial URL

                                

Initial Description
This batch script writes a temporary .vbs file which will invoke a UAC prompt to open an administrator command prompt.  This makes it easy to create a shortcut to an admin prompt.

Initial Title
Batch script to open an Administrator CMD shell

Initial Tags
command

Initial Language
PHP