Link to home
Start Free TrialLog in
Avatar of BTTraining
BTTrainingFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Wait 10 seconds in WinPE environment?

I've got an interesting problem; I've developed a set of bootable USB sticks on which I've put WinPE (64-bit Vista version).  When startnet.cmd is called, it executes wpeinit, which takes about 7 secs to complete, and then I run my scripts.
However, the script (map.bat) attempts to make a network connection, but I find system cannot find the network path.  If I wait 10 seconds and run the map.bat again, it works fine.
So I started trying to 'wait' in my script.
To cut a long story short, I can't ping x.x.x.x -n 1 -w 10000, because IP isn't yet configured (even 0.0.0.0) and errors without waiting.  I've tried;
attempt map 1
ping for 2 seconds
attempt map 2
ping for 2 seconds
attempt map 3
ping for 2 seconds

I've tried computerhope's sleep command, but as it's a WinPE x64 env, the program doesn't run.

My latest attempt was to do an ipconfig /renew as the first command, but but it complains of no adapter being in the correct state; so I suspect the network driver isn't 'up' yet.

Any ideas?
Avatar of johnb6767
johnb6767
Flag of United States of America image

ping -n 10 localhost

maybe a few bogus "systeminfo>NUL" commands? Systeminfo.exe usually takes 3-4 seconds (not sure about a PE environemnt, but >NUL at least keeps teh errors offscreen.....
It's been awhile since I did .BAT files, but what about a FOR-NEXT loop to kill about 10 seconds?
a one line vbscript perhaps:

@echo off
echo sleep 10>wait.vbs
cscript wait.vbs

if ip isnt up at all then the localhost probably wont respond either.

or you could use choice.com if that is on there and works.

Or if you want an exe there is an ancient one called waitsecs.exe on my downloads page at http://www.dragon-it.co.uk/

only passing, sure youll have an answer out of that lot somewhere or someone else will shortly.

Steve
Avatar of BTTraining

ASKER

Thanks for the suggestions.  
@John, the localhost option isn't any different from pinging 127.0.0.1, and as IP isn't up yet, that doesn't cause the delay I want.
I've thought of running commands >NUL a few times, but I'm struggling to think of one that will cause a long delay rather than an instant error (such as ipconfig /renew).
I'll try systeminfo, though I can't imagine why WinPE would need it

@dragon-it, I'll give that a go, my PE environment supports scripting, so I'd imagine cscript is in there.  The only trouble I'm encountering is returning from an external program back in the flow of this one.  For instance, I wrote a script called both.bat. it contains two lines;

*****
REM first script called
testFirst.bat

REM second script called when first is finished
testSecond.bat

*****

testFirst.bat has one statement ; echo First Worked
testSecond.bat also has one statement; echo Second worked

When it runs, only the first string (First Worked) is output.
I've tried &&ing them and it sitll doesn't appear to work.

In old DOS scripts I remember adding & to a line to have it run in the background, will that help here?
you can use call to go to another script and come back.  cscript running a vbscript is just a program effectively so it just carries on at next statement anyway.

You can do multiple commands onoone line with & like you say.

BTW My previous example was somewaht flawed, I missed out "wscript" and paused for 10ms not 10s :-)

@echo off
echo wscript.sleep(10000)>wait.vbs
cscript wait.vbs

You can point the wait.vbs elsewhere, e.g. %temp% or have it already there rather than create it, i.e.

@echo off
echo wscript.sleep(10000)>"%temp%\wait.vbs"
cscript "%temp%\wait.vbs"

or you could have a file already there called wait.vbs which pauses the number of seconds from command line, e.g.

'save this as wait.vbs
wscript.sleep (WScript.Arguments(0) * 1000)

and run it with:

cscript //nologo wait.vbs 10

Obviously you could add error checking and the like but not really needed for this !

Steve
ASKER CERTIFIED SOLUTION
Avatar of FirstSentinel
FirstSentinel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not a bad plan in there actually... rather than a forced wait for 10 secs use a PING and keep looping until it doesn't return an error... I wasn't thinking PE specific just answering the ask for a 10 sec delay!
Going to try this today, will let you know how it goes!
Just updated my boot sticks, I went with The Deployment Guys via FirstSentinel's solution, love the simplicity of it, and it works a treat.  Zero touch rebuilds of XP have just been done on 40 PCs this afternoon, brilliant.  Thanks to Dragon-it for your efforts too!