我有一个小的 vbs 脚本:
Set UAC = CreateObject("Shell.Application")
UAC.ShellExecute "C:\bin\addtopath.bat", chr(34) & "C:\bin" & chr(34), "", "runas", 1
C:\bin\addtopath.bat
存在,我从这个问题中得到了一些想法。这里发生的是 acmd
打开并立即关闭,我无法识别它所说的内容。我怎么知道出了什么问题?
C:\bin\addtopath.bat
:
pause
echo %1
pause
:: 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", chr(34) ^& %1 ^& chr(34), "", "runas", 1 >> "%temp%\getadmin.vbs"
pause
"%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