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
2

2 Answers

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 
7

Here's the final working script all cleaned up and working in both Windows 10 and 11

@echo off
SETLOCAL EnableExtensions
set EXE=TOTALCMD64.EXE
taskkill /f /im explorer*
"%~dp0PowerRun_x64.exe" /SW:0 "%EXE%"
:LOOP
timeout /t 3 /nobreak
FOR /F %%x IN ('tasklist /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto LOOP
start "" explorer.exe
endlocal &exit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest