# Inserting a 'wait' command into a batch file



## CaptainTrips (Jul 9, 2011)

Simple question.  I've created a batch file to do a number of things, but I need to insert a 'wait' time between some of the steps.  I seem to remember being able to do this with a DLL in the past, but I could be wrong.  I've found some ways to do it with additional programs, or creative ways (the method I am using now is to just ping the local host).  is there a simple "wait 10000" or such?

Any ideas?

Just to clarify, this is not the "pause" command.

Thanks in advance!


----------



## NyxCharon (Jul 9, 2011)

why exactly do you need to insert the delay, if i may ask?


----------



## CaptainTrips (Jul 11, 2011)

NyxCharon said:


> why exactly do you need to insert the delay, if i may ask?



I've solved the problem, I'll explain below.  What I had going was a batch file that put my monitor to sleep and locked my PC.  I have roomates and wanted a step of protection.  they're pretty green to computers, so a simple windows password would stop them if they came snooping.

So if I locked the PC, then put the monitor to sleep, the PC would lock, but the monitor wouldn't sleep.  If I put the monitor to sleep, then locked the PC, the monitor would sleep, the PC would lock, waking up the monitor.  I was hoping a delay might solve this.

But, I found a different neat utility that controls a lot of basic little functions of your PC, like putting your monitor to sleep (with an optional delay), open CD drives, volume changes, lots of window and icon manipulations etc.  It's called nircmd.

So my batch file now reads:
rundll32.exe user32.dll, LockWorkStation
"C:\Nircmd\nircmd.exe" cmdwait 2000 monitor off

works like a charm.


----------



## mrgcat (Jul 11, 2011)

Nice. Pretty decent stuff.
I don't use batch files that much. Though reading this I realise how capable they are of doing some quite cool stuff


----------



## Cromewell (Jul 12, 2011)

> But, I found a different neat utility that controls a lot of basic little functions of your PC, like putting your monitor to sleep (with an optional delay), open CD drives, volume changes, lots of window and icon manipulations etc


Is there a reason you want to script that kind of stuff? Because your OS can all that stuff as well.


----------



## CaptainTrips (Jul 12, 2011)

If there is, I wasn't aware of it.  How would I go about it in Win7 Pro?



Cromewell said:


> Is there a reason you want to script that kind of stuff? Because your OS can all that stuff as well.


----------



## Cromewell (Jul 12, 2011)

CaptainTrips said:


> If there is, I wasn't aware of it.  How would I go about it in Win7 Pro?


This isn't the command I was thinking of but it should result in the monitor powering off after a minute of inactivity.

powercfg -change -monitor-timeout-ac 1

The command to set the system to hibernate/standby (depends on power config options) is rundll32 powrprof.dll, SetSuspendState

There is one for monitor too, but I can't seem to find it right now. Nircmd works, (as does some other 3rd party tools) but they do require you to install them on the machine you want to use your batch files on.


----------



## CaptainTrips (Jul 13, 2011)

I knew a few of them could be done with system32 and such.  I'm just not too savvy on what it can do, and how.  Thanks.

Nircmd doesn't require an install.  It's just a single exe, a command line tool with a lot of launch modifiers.  Here's everything it can do.  Some of them seem silly to me, like copying all your desktop shortcuts, but I suppose someone out there needs that feature.



Cromewell said:


> ... Nircmd works, (as does some other 3rd party tools) but they do require you to install them on the machine you want to use your batch files on.


----------



## claptonman (Jul 13, 2011)

Off topic question, but are you the same captaintrips from GTU? (You'd understand that if you were...)


----------



## CaptainTrips (Jul 13, 2011)

I am not.  I am actually a sentient strain of the super flu that has been given access to the Internet by the Sombra Corporation.



claptonman said:


> Off topic question, but are you the same captaintrips from GTU? (You'd understand that if you were...)


----------

