批处理文件-如何检查Runas是否已成功运行

时间:2019-07-11 13:48:34

标签: windows batch-file cmd error-code

我正在使用以下代码运行一些应用程序以开始我的项目。

主要批处理代码

@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代码:

@echo off
start "" "D:\AppX.exe"
start "" "D:\AppY.exe"
start "" "D:\AppZ.exe"

在管理批处理文件中返回 EXIT 0 EXIT / B 0 无效。

如何检查 runas 命令是否已成功处理?

0 个答案:

没有答案