How do I pause my batch script without having to add a pause command?
Sometimes I need to do certain Windows tasks as TrustedInstaller like copying, deleting, renaming, moving files/folders, etc. So I created this batch script that kills Explorer.exe and launches Total Commander as TrustedInstaller using PowerRun.
I would like the script to launch Total Commander (and I do whatever tasks I need to do) then when I close Total Commander, Explorer.exe automatically starts without the need to add a pause in the script.
I tried with "start "" /wait" and "call" but I cannot make them work with PowerRun.
@echo off
taskkill /f /im explorer*
"%~dp0PowerRun_x64.exe" /SW:0 "TOTALCMD64.EXE"
pause
start "" explorer.exe
exit
Solution 1:
Alternative without using a for loop and using only one label
@echo off
>nul 2>&1 %__APPDIR__%Net.exe file || goto :Elevate
SetLocal EnableExtensions & Set "_EXE=TOTALCMD64.EXE"
Set "_KEY="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoRestartShell /t REG_DWORD /d 0 /f"
Reg Add %_KEY%
Taskkill /f /im explorer*
"%~dp0PowerRun_x64.exe" /SW:0 "%_EXE%"
:LOOP
Timeout /nobreak 03
Tasklist | find /i "%_EXE%" >nul && goto LOOP
Reg Add %_KEY:0=1%
Start "" /b explorer.exe
endlocal & goto eof
:Elevate
SetLocal EnableDelayedExpansion
For %%i in (%*)do Set "_Args=!_Args! "%%~i""
Set "_cmd_Args= /x/d/q/c "%~0" !_Args!"
Set "_ps1=%__APPDIR__%\WindowsPowerShell\v1.0\PowerShell.exe"
%_ps1% -nop -c start $env:windir\system32\cmd.exe -Arg $env:_cmd_Args -v runas
endlocal & exit /b