godofgrunts
godofgrunts

Reputation: 262

Can't get batch to logout when it's done

I have a .bat that I've wrote to automate an install of a piece of software I have to install all the time at work. (I can't use powershell because a lot of the machines are XP still)

Near the end, the script is supposed to clean itself up and and logout, but I can't get it to log out for some reason.

taskkill /f /im explorer.exe>nul 2>&1
set _sd=%~dp0
cd /d c:\
del "%_sd%md5sum.exe"
...
del "%_sd%RUN-AS-ADMIN.bat"
wait 2
shutdown -f -l

Upvotes: 2

Views: 70

Answers (2)

MichaelS
MichaelS

Reputation: 6042

There is no wait command in CMD. There is timeout for Win7+ but not for XP. To implement a kind of a timeout you'll have to use for example ping 127.0.0.1 -n 6 > nul. This will make your system "wait" for 5 seconds. You can modify the timeout by replacing 6 with any other value. If you want a timeout of X seconds, replace 6 with X+1.

Upvotes: 2

Mike Steele
Mike Steele

Reputation: 111

EDIT: Made a stupid mistake making this, fixed it up.

Try this instead:

taskkill /f /im explorer.exe>nul 2>&1
set _sd=%~dp0
cd /d c:\
del "%_sd%md5sum.exe"
...
del "%_sd%RUN-AS-ADMIN.bat"
pause
shutdown -f -l

All I did was make it so that the wait is replaced with pause

I did some looking around, and I couldn't find any native commands that make the batch file delay and automatically continue, so this is the closest I can find. (Assuming the computer you're using this on is a Windows XP)

If you don't use a Windows XP for the batch file, use this instead:

taskkill /f /im explorer.exe>nul 2>&1
set _sd=%~dp0
cd /d c:\
del "%_sd%md5sum.exe"
...
del "%_sd%RUN-AS-ADMIN.bat"
timeout /t 2 >nul
shutdown -f -l

The timeout acts as a delay, however, it is unfortunately not a native command on Windows XP, but it is on Windows 7+ (Unsure about vista) Hope this helps :)

Upvotes: 2

Related Questions