Created
January 18, 2013 15:58
-
-
Save prongs/4565567 to your computer and use it in GitHub Desktop.
batch file for adding a directory to system path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: BatchGotAdmin | |
:------------------------------------- | |
REM --> Check for permissions | |
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" | |
REM --> If error flag set, we do not have admin. | |
if '%errorlevel%' NEQ '0' ( | |
echo Requesting administrative privileges... | |
goto UACPrompt | |
) else ( 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" ) | |
pushd "%CD%" | |
CD /D "%~dp0" | |
:-------------------------------------- | |
echo %1 | |
pause | |
setenv -a PATH %1 | |
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set UAC = CreateObject("Shell.Application") | |
UAC.ShellExecute "C:\bin\ADDTOP~1.BAT", ""C:\bin"", "", "runas", 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment