So you want to pause a batch file for a few seconds. Unfortunately windows doesn’t provide a very simple way of doing this. I wanted to run ‘netstat -b’ 25 seconds after a user logged into their computer as to give the computer enough time to start up all background applications. But, there is no wait function in batch files. Well I found a workaround. If you use the ‘-n’ argument with the ping command you can specify the amount of time to run a ping for. Thus ping -n 60 127.0.0.1 will ping your local host for 60 seconds. This will more or less keep the batch file at a standstill for a specified number of seconds before continuing. In my case I used it for a pause in a login script.
title login script
color 1f
set name=%computername%
ping -n 25 127.0.0.1
echo %computername% >> g:\%name%.log
date /T >> g:\%name%.log
time /T >> g:\%name%.log
netstat -b >> g:\%name%.log
echo *********************************************** >> g:\%name%.log
echo *********************************************** >> g:\%name%.log
echo *********************************************** >> g:\%name%.log
echo *********************************************** >> g:\%name%.log
echo *********************************************** >> g:\%name%.log
In this script the ‘G’ Drive is a mapped drive for administration. When a user logs in they will open the log stamp it with their computer name, the date and the time. Then the netstat output, followed by a few lines of asterisks to separate the uses visually. I have an OU with this script applied to it. If I suspect a user is doing something sketchy I add them to this OU, to do a little snooping.
[ad]