Я использую следующий код для запуска некоторых приложений, чтобы начать работу с моим проектом.
Основной пакетный код
@echo off
:check_permission
echo Detecting administrative permissions...
net session >nul 2>&1
if NOT %errorlevel% == 0 (
REM if not an admin, ask for password to run admin priviliege required apps
runas /user:sys-xyz\naveenkumar batchfile_admin.bat
REM "THE ERRORLEVEL AT THIS STAGE IS 2 EVEN IF PASSWORD IS PROVIDED CORRECTLY"
if %errorlevel% == 0 (
goto :runapp
) else (
echo =========================================
echo "ERROR: Required .bat with admin privilege is not successfully completed"
goto :eof
)
) else (
echo Opening apps with admin privilege
batchfile_admin.bat
goto :runapp
)
:runapp
echo Opening apps with user privilege [only if cmd is opened in admin mode]...
start "" "D:\App1.exe"
start "" "D:\App2.exe"
start "" "D:\App3.exe" -nogui
:eof
echo =========================================
echo !!! BATCH FILE COMPLETED !!!
batchfile_admin code:
@echo off
start "" "D:\AppX.exe"
start "" "D:\AppY.exe"
start "" "D:\AppZ.exe"
Возврат EXIT 0 или EXIT / B 0 в командном файле администратора не помог.
Как мнепроверить, успешно ли обработана команда runas ?