We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Batch file to restart PC

gisvpn
gisvpn asked
on
Medium Priority
25,831 Views
Last Modified: 2009-02-10
Is it possible to write a batch file which restart my computer ?

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
What operating system?
You can do this in most OSs...

Try shutdown /? from a command line to get an idea...
CERTIFIED EXPERT
Top Expert 2006
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
If it makes a difference please could you let me know for the following (",)

Windows XP
Windows 2000
Windows 98
Windows 95
Windows NT

Thank you.. Have increased the points :)
CERTIFIED EXPERT
Top Expert 2007

Commented:
In windows 9x/ME:

@start "C:\WINDOWS\RUNDLL32.EXE user,exitwindows"

See other examples here: http://www.robvanderwoude.com/index.html
CERTIFIED EXPERT
Top Expert 2007

Commented:
My last post is for many operating systems and scripts.
Just simply create a batch file with the appropriate command in it...
CERTIFIED EXPERT
Top Expert 2007
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2007

Commented:
Another good link: http://home.wanadoo.nl/scripting/topics/f10/ultimatebb.cgi-ubb=print_topic;f=10;t=000035.htm

Win31:
 ECHO G=FFFF:0000 ¦ DEBUG
Win9x:
 RUNDLL USER.EXE,ExitWindows
 RUNDLL USER.EXE,ExitWindowsExec

Win9x/ME:
 RUNDLL32 SHELL32.DLL,SHExitWindowsEx n
(where n=1 to shutdown.  0=Logoff, 2=Reboot, 8=PowerOff (if hardware supported)

NT(/2K):
 RUNDLL32 USER32.DLL,ExitWindowsEx
 (with ResourceKit):
   SHUTDOWN /L /T:10 /Y /C

XP (/2k with resource kit):
 SHUTDOWN -s -t 01



Using KIX:
  $RC = SHUTDOWN( "\\server", "Shutting down...", 10, 1, 0 )

Author

Commented:
Sirbounty

Do you know how to install the DevCon Command Line utility onto a Windows 2000 PC ?

I have downloaded the .ZIP file from Microsoft however Devcon does not work... cant find any install instructions from MS ?

Can you help ?

Thanks Ollie
CERTIFIED EXPERT
Top Expert 2007

Commented:

Author

Commented:
Hi Sirbounty.

Thanks for the link.. for some reason if you download it from here  http://support.microsoft.com/?kbid=311272 it gives you a .exe which contains 3 zipped files.

Apparently you have to unzip these and place them in PATH ( C:WINNT\system32 ).

Works great now..

However, with Devcon Reboot, how can i add a delay to the reboot ?
CERTIFIED EXPERT
Top Expert 2007

Commented:
I dont' know that it has a native way of delaying the reboot...(try Devcon /? or Devcon Help)

Otherwise, place a 'homemade' timer before the reboot:
------------------
ping 127.0.0.1 -n 25
devcon restart
-------------------
(ping's localhost 25 times before continuing

Author

Commented:
ok thank you :)

Commented:
My two cents.

Windows 95 is notorious for not restarting with a RUNDLL command. If you want to reboot a Win95 PC from a batch file, you might want to look at:

http://www.rjlsoftware.com/software/utility/shutdown/

This is for a simple shutdown utility that will work from the command line and its free.

I tried it with a batch file and it worked beautifully.

It also works with just about every Win version.

Commented:
So, to take this batch file creation theme one step further, I assume it's possible to write a scheduled restart batch file...in other words, a restart batch file that gets executed at a specific time. Does anyone have any ideas on what the best way would be?

Before the question gets asked, this is specifically for Windows XP (Pro).

thanks for any and all input,

JDH
CERTIFIED EXPERT
Top Expert 2007

Commented:
XP includes a shutdown command...
SHUTDOWN /? from a command prompt should get you started...

Commented:
yes, I already know the correct command...it is: shutdown -r -f

My question was not what command to use, but rather HOW to write a batch file that would be automatically run at a particularly time. So, what to put IN the batch file and how to make it run at regularly recurring intervals (similar to a cron-job in UNIX)?

Can anyone offer any suggestion?

JDH
CERTIFIED EXPERT
Top Expert 2007

Commented:
Don't recall cron-job myself, but just use task scheduler to schedule it - your batch file would include the line you've stated above...
If you need further assistance, you're better off opening a new question, see: http:help.jsp#hi107

Commented:
Yeah, you're right....my bad. I think you have answered my question though, so thank you.

-You're the man, Senior Bounty!

JDH
CERTIFIED EXPERT
Top Expert 2007

Commented:
: )
Happy to help..
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.