Solved

Batch file to restart PC

Posted on 2004-03-23
19
25,448 Views
Last Modified: 2009-02-10
Is it possible to write a batch file which restart my computer ?

0
Comment
Question by:gisvpn
  • 10
  • 4
  • 3
  • +2
19 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
What operating system?
You can do this in most OSs...

Try shutdown /? from a command line to get an idea...
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 250 total points
Comment Utility
Hi gisvpn,

www.robvanderwoude.com/shutdown.html

Sunnycoder
0
 

Author Comment

by:gisvpn
Comment Utility
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 :)
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
In windows 9x/ME:

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

See other examples here: http://www.robvanderwoude.com/index.html
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
My last post is for many operating systems and scripts.
Just simply create a batch file with the appropriate command in it...
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 250 total points
Comment Utility
As requested, create each of these in a batch file...

Windows XP:
@SHUTDOWN -s -t 01

Windows 2000:
(using DEVCON.  Free here: http://support.microsoft.com/?kbid=311272 - you can 'reboot': DEVCON Reboot)
To shutdown - copy SHUTDOWN from XP or use SHUTDOWN.EXE from the Windows 2000 Resource Kit
or, use PSShutDown from the free PSTools: http://www.sysinternals.com/ntw2k/freeware/pstools.shtml
 SHUTDOWN /L /T:10 /Y /C
 PSSHUTDOWN \\my2ksrv -K -F -T 20  

Windows 98:
 RUNDLL32 KRNL386.EXE,exitkernel

Windows 95:
 RUNDLL USER.EXE,ExitWindows

Windows NT: (again, using either Shutdown from the resource kit, or PSShutdown)
 SHUTDOWN /L /R /T:0 /Y

-------------
From the link - offers both Shutdown and reboot options:
>>>

Shutdown and Reboot
 

OS (1) Command line Effect Remarks
 DOS ECHO G=FFFF:0000 ¦ DEBUG  Reboot Warm boot, sometimes cold boot.
May not work with "exotic" memory managers, like Quarterdeck's QEMM or DesqView; in that case, use RESET.COM instead.
Win31* ECHO G=FFFF:0000 ¦ DEBUG  Task Manager popup And sometimes reboot
Win9* RUNDLL USER.EXE,ExitWindows  Shutdown (2)  
Win9* RUNDLL USER.EXE,ExitWindowsExec  See Remarks Win95: various results, usualy fast shutdown (and lock PC), sometimes restart Windows, sometimes reboot.
Win98: Restart Windows, sometimes reboot.
Win9* RUNDLL SHELL.DLL,RestartDialog  Restart dialog "System Settings Changed, Do you want to restart your computer now?" dialog
Win98 RUNDLL32 KRNL386.EXE,exitkernel  Poweroff Poweroff for ATX boards only, otherwise normal shutdown (3)
Win98/ME RUNDLL32 SHELL32.DLL,SHExitWindowsEx n  See Remarks n can be any combination (sum) of the following numbers: (4)
0    Logoff
1    Shutdown
2    Reboot
4    Force
8    Poweroff (if supported by the hardware)
 
Win98/ME RUNONCE.EXE -q  Reboot (4)  
NT4 See Reboot NT on my Solutions found in alt.msdos.batch page Reboot Reboot immediately
NT4 RUNDLL32 USER32.DLL,ExitWindowsEx
RUNDLL32 USER32.DLL,ExitWindowsEx  Logoff Most systems require the command to be called twice before logging off
NT4+RK
W2K+RK SHUTDOWN /L /R /T:0 /Y  Reboot Immediate shutdown & reboot
NT4+RK
W2K+RK SHUTDOWN /L /T:10 /Y /C  Delayed shutdown Shutdown in 10 seconds, close without saving.
Can be stopped during those 10 seconds using SHUTDOWN /A
NT+ (1) PSSHUTDOWN \\mynt4srv -K -F -T 20  Delayed poweroff Poweroff \\mynt4srv after a 20 seconds delay
Can be aborted using PSSHUTDOWN \\mynt4srv -A
Uses PSSHUTDOWN.EXE from SysInternal.com's PS Tools
NT+ (1) PSSHUTDOWN \\myw2ksrv -O -F -T 0  Logoff Immediately logoff console user on \\myw2ksrv
Uses PSSHUTDOWN.EXE from SysInternal.com's PS Tools
W2K (5) DEVCON Reboot  Reboot Requires Microsoft's DEVCON utility
W2K Click here and learn how to shutdown a remote Windows 2000 computer Shutdown GUI, no command line
XP SHUTDOWN -r -t 10  Delayed reboot Reboot after a 10 seconds delay.
Can be stopped during those 10 seconds using SHUTDOWN -a
XP SHUTDOWN -s -t 01  Delayed shutdown Shutdown after a 1 second delay, NO poweroff.
TS LOGOFF 16 /SERVER:termserv1  Logoff Logoff session 16 on Terminal Server TERMSERV1.
Use the QUERY USER command to find out which session ID belongs to whom.
More Terminal Server commands here.
TS TSSHUTDN 45 /SERVER:termserv1 /POWERDOWN /DELAY:20 /V  Delayed poweroff Notify all users on Terminal Server TERMSERV1, logoff all Terminal Server sessions after 45 seconds, wait another 20 seconds, and then shut down Terminal Server TERMSERV1 and power off.
See my Terminal Server Commands page for the exact syntax.
Kix $RC = SHUTDOWN( "\\server", "Shutting down...", 10, 1, 0 )  Delayed shutdown Shutdown \\server in 10 seconds, with message, close without saving, no reboot
Kix $RC = SHUTDOWN( "\\server", "", 0, 1, 1 )  Reboot Immediate shutdown & reboot \\server, without a message
Kix $RC = LOGOFF( 1 )  Logoff Forcing applications to close.
Use 0 instead of 1 if you don't want to force applications to close
Perl InitiateSystemShutdown( $sComputer, $sMessage, $uTimeoutSecs, $bForce, $bReboot )    General syntax (ActivePerl for Windows only)
Perl InitiateSystemShutdown( "", "", 0, 1, 1 )  Reboot Immediate reboot without message, force applications to close without saving data
Perl InitiateSystemShutdown( "", "Going down...", 10, 0, 1 )  Delayed reboot Reboot after 10 seconds, with message and without forcing applications to close
Perl InitiateSystemShutdown( "10.0.1.16", "Sorry", 5, 1, 0 )  Delayed shutdown Shutdown of remote computer after 5 seconds, with message and forced closing of applications
Regina Rexx RC = W32SysShutdown( how [,force] )    General syntax (Regina Rexx for Windows with W32Funcs only).
how can be either Reboot, Logoff, Poweroff or Shutdown.
force can be either Force or Noforce.
Regina Rexx RC = W32SysShutdown( "P", "F" )  Poweroff Immediate shutdown and poweroff, forced closing of application
Regina Rexx RC = W32SysShutdown( "L", "N" )  Logoff Logoff, prompt for saving unsaved data
WSH [1] Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
[2]
[3] for each OpSys in OpSysSet
[4]     OpSys.Reboot()
[5] next  Reboot Requires WMI.
Remove [line numbers].
(Found in a forum posting by Alex K. Angelopoulos on www.developersdex.com)
WSH Replace line 4 in the script above with this one:
[4]     OpSys.Shutdown()
to shut down the PC instead of rebooting it. Shutdown But no poweroff.
 
See my WSH page for examples on how to reboot or shut down remote computers too.
WSH [1] Const EWX_LOGOFF = 0
[2]
[3] Set wmi = GetObject("winmgmts:{(Shutdown)}")
[4] Set objSet = wmi.InstancesOf("Win32_OperatingSystem")
[5]
[9] For Each obj in objSet
[6]     Set os = obj
[7]     Exit For
[8] Next
[9]
[10] os.Win32Shutdown EWX_LOGOFF  Logoff Requires WMI.
Remove [line numbers].


<<<
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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 )
0
 

Author Comment

by:gisvpn
Comment Utility
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
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:gisvpn
Comment Utility
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 ?
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
0
 

Author Comment

by:gisvpn
Comment Utility
ok thank you :)
0
 
LVL 1

Expert Comment

by:srodolff
Comment Utility
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.
0
 

Expert Comment

by:J_D_H
Comment Utility
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
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
XP includes a shutdown command...
SHUTDOWN /? from a command prompt should get you started...
0
 

Expert Comment

by:J_D_H
Comment Utility
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
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
0
 

Expert Comment

by:J_D_H
Comment Utility
Yeah, you're right....my bad. I think you have answered my question though, so thank you.

-You're the man, Senior Bounty!

JDH
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
: )
Happy to help..
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now