Monday, September 29, 2008

Restarting Windows XP from a startup script is not easy

Yes, they are still out there running the big businesses!

Today, I was messing with a startup script, that should restart the PC - but WMI did not do it and shutdown.exe just returned device is not ready. This should have been fixed in SP2 - at least some KBs claims that - but that is clearly not the case.

Eventually, I found a way around: Create an AT-job to do the restart. That worked. But it was too slow as AT-jobs needs to be postponed at least a minute.

Finally, good old Sysinternals came to the rescue - this time in the shape of psexec. Sysinternals have saved the day many times and back in the late nineties you could simply not lock down and figure out where to relax security on an NT 4 without regmon and filemon. Anyway, back to today. This was how I solved my present problem -

psexec -accepteula -sd shutdown -r -t 5



 



-sd tells it to start the process in system context (the s) and detached (d) as I did not want to wait for the command - I wanted my script to finish as long as it had time to do so.

5 comments:

Anonymous said...

Try:

shutdown /r /f /t 5

Per Østergaard said...

Hi Shay

I did that - but just keeps getting device not ready.

My situation is special in another way: I just changed the domain membership before wanting to restart. That gave me problem with accessing files from sysvol so, consequently, I copy these files to C: first and executes them from there. This could explain why restart does not work - but I'm running as SYSTEM, so things should work.

Anonymous said...

It's -accepteula, not -accesseula

psexec.exe -accepteula -sd shutdown -r -t 05

Per Østergaard said...

naturally ;) (fixed)

Unknown said...

Thanks Per - you just saved my day!

I had the exact same problem. Being a big fan of SysInternals as well, I was trying to solve the problem using psshutdown - until I read your solution, which works beautifully!