This is G o o g l e's cache of http://www.experts-exchange.com/Programming/Q_20632389.html as retrieved on Aug 26, 2005 12:43:18 GMT.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
This cached page may reference images which are no longer available. Click here for the cached text only.
To link to or bookmark this page, use the following url: http://www.google.com/search?q=cache:Wh46OCh941wJ:www.experts-exchange.com/Programming/Q_20632389.html


Google is neither affiliated with the authors of this page nor responsible for its content.

Programming: Shutdown using a .BAT file?
August 26, 2005 - 05:43AM PDT
Page Options
Who's using EE?
Who's Using EE
You're in good company
jkr Page Editor
Programming
jkr
Featured Expert Featured Expert
cookre
Ask An Expert Now!

Search 1,331,618 Solutions
asked by steroyle on 05/31/2003 11:19AM PDT

Is it possible to create a bat file that when run, will shutdown or restart your computer. If so where would I find information on doing this?


Get your IT Solutions GUARANTEED!
Get instant answers from Experts Exchange knowledge base
keywords 
More IT professionals have found their answers instantly at Experts Exchange than at any other IT site
Choose a technology channel and SEARCH or ASK AN EXPERT
Operating Systems:
Linux
X-Windows
Macintosh
MS-DOS
OS/2
Solaris
Unix
Windows 2000
Windows NT
Windows ME
Windows XP
Windows 98
Windows 95 & 3.x
Open BSD
Windows Server 2003
FreeBSD
AIX IBMs UNIX OS
Databases:
MS Access
Berkeley DB
Crystal Reports
FoxPro
IBM UDB
Interbase
Microsoft SQL
Mysql
Oracle
Sybase
Btrieve
FileMaker
DB Reporting
GIS & GPS
ERP
PostgreSQL
EAI
Storage:
Security:
Linux Security
Windows Security
Unix Security
Bugs and Alerts
Firewalls
Programming:
Game Dev.
Platforms
Languages
Wireless
Web Languages
Software Design
Web Development:
App Servers
Web Dev. Software
Web Servers
Web Languages
Browser Issues
App Service Providers
Online Marketing
Hosting
Graphics
Lotus Domino Admin
Hardware:
Routers
Desktops
Mac Comm.
Modems
New Users
Microchips
Printers
Scanners
Handhelds/Wireless
Laptops/Notebooks
Notebooks Wireless
Networking:
Linux Net.
Mac Net.
Netware
OS/2 Net.
Unix Net.
Win95 Net.
WinNT Net.
Email/GroupWare
Broadband
Microsoft Network
VoIP/Voice over IP
Video Conferencing
Citrix
Sharepoint
Applications:
Mac Apps
MS Office
OS/2 Apps
Viruses
SAP
Lotus Smart Suite
Email
Graphics
WordPerfect Office Suite
MultiMedia Applications
Productivity Applications
EAI
Microsoft Project
CAD
CRM
Groupwise
ERP
Miscellaneous:
Lounge
Puzzles & Riddles
Philosophy & Religion
Math & Science
URLs
New Net Users
Games
Community Support:
EE Bugs
Expert Input
New Topics
Suggestions
New to EE?
CleanUp
Feedback
Accepted Answer from udosoft
Date: 05/31/2003 12:54PM PDT
Grade: A
Accepted Answer

OS? for example
w2k use shutdown.exe from reskit, winxp contains it already. Properties. In the Target box, append the command line switch -l (to log off), -s (to shut down), or -r (to reboot). (-txx time delay)
(Win 9x)
The line should be as follows:

For RESTART Windows:
C:\WINDOWS\RUNDLL.EXE user.exe,exitwindowsexec

For SHUT DOWN Windows:
C:\WINDOWS\RUNDLL32.EXE user,exitwindows

for most OS:

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
NT+RK (1) SHUTDOWN /L /R /T:0 /Y  Reboot Immediate shutdown & reboot
NT+RK (1) 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
2000 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].
Posted by Michael Harris on microsoft.public.scripting.vbscript.
 
My Logoff.vbs combines this code with that of the reboot and shutdown commands, and allows logoff of remote computers as well.
OS/2 START /PM SHUTDOWN && EXIT  Shutdown Will still stop and ask for confirmation if a non-PM application is active
OS/2 SETBOOT /IBD:C:  Reboot Unconditional shutdown & reboot
OS/2 SETBOOT /IBA:nonsense  Shutdown Unconditional shutdown & failing reboot.
Needs Boot Manager installed.
Will reboot, no questions asked, and then stop if nonsense is an invalid Boot Manager menu entry (which, in this case, is exactly what we want).
OS/2 LOGOFF  Logoff Both LAN Server client and Peer

 

 
Notes:   1   DOS    MS-DOS or PC-DOS
 Win31*  Windows 3.1, 3.11 or 3.11 for Workgroups
 Win9*  Windows 95 or 98
 Win98  Windows 98
 Win98/ME  Windows 98 or Windows Millennium Edition (ME)
 NT4  Windows NT 4 (not Windows 2000)
 NT  Windows NT 4 or Windows 2000
 NT+RK  Windows NT 4 or Windows 2000 with the appropriate Resource Kit
 2000  Windows 2000
 XP  Windows XP
 TS  Windows NT 4 Terminal Server Edition or Windows 2000 (Advanced) Server with Terminal Server installed
 Kix  Windows (any) with KiXtart
 Perl  Windows (any) with ActivePerl
 Regina Rexx  Windows (any) with Regina Rexx and W32Funcs
 WSH  Windows Script Host
 OS/2  OS/2 Warp 3 and 4, LAN Server and Warp Server
 2 Thanks for Bill James and Tom Lavedas, for the information on RUNDLL.
Find more RUNDLL examples I collected on my RUNDLL page.
 3 Thanks for Sasha Predii for posting this information on www.diskovod.ru.
Find more RUNDLL examples I collected on my RUNDLL page.
 4 See article Q234216 in the Microsoft Knowledge base for more information.
Thanks for Alec Soroudi for pointing out this information.
Windows NT also has a RUNONCE.EXE, but I am not sure what its purpose is -- RUNONCE.EXE -q does not shut down NT.


(Win 98/ME)

C:\WINDOWS\RUNDLL32 SHELL32.DLL,SHExitWindowsEx n

Where n is one of the following values, depending on the task you want to accomplish:

n=0 LOGOFF: Shuts down all running processes, logs the user off, then restarts the Windows shell. (Same as Logoff on the Start Menu.)
n=1 SHUTDOWN: Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped.
n=2 REBOOT: Shuts down the system, then restarts it. (Same as Start Menu | Shutdown | Restart.)
n=4 FORCE: Forces all processes to terminate ó in effect, shuts down all running programs. When this flag is set, Windows does not query running applications to inform them that Windows is shutting down. This can cause the applications to lose data, therefore, you should only use this flag in an emergency.
n=8 POWEROFF: Exits Windows, then turns off the computerís power (provided the computer supports the power-off feature).
n=-1 RESTART EXPLORER: Quickly closes Explorer (i.e., the Windows desktop), then lets it restore itself.


Comment from steroyle
Date: 05/31/2003 02:47PM PDT
Author Comment

thats a lot of info and kinda confusing to me. Do I just copy and paste the text into a txt file and rename .bat Im not too sure which is code and which isnt. Sorry if im wasting your time but im new to bat files.

Comment from foobar43
Date: 06/01/2003 02:56AM PDT
Comment

windows xp already got it:

command line: shutdown                   - shutdown computer
command line: shutdown -r                - reboot computer


Comment from MellowD0c
Date: 06/01/2003 08:24AM PDT
Comment

On Win9x systems try this:

Create a file in notepad named Shutdown.bat and have this line only in it.

@exit

save and run it. It should shutdown your system.

Comment from MellowD0c
Date: 06/01/2003 08:27AM PDT
Comment

Again,

You could try this too and it should work as well:

You can use either of the following commands in a batch file to restart Windows 98 automatically:

runonce.exe -q

rundll32.exe shell32.dll,SHExitWindowsEx n

where n is one, or a combination of, the following numbers:

0 - LOGOFF

1 - SHUTDOWN

2 - REBOOT

4 - FORCE

8 - POWEROFF

The above options can be combined into one value to achieve different results. For example, to restart Windows forcefully, without querying any running programs, use the following command line:

rundll32.exe shell32.dll,SHExitWindowsEx 6

NOTE: Using the FORCE option can cause programs to lose data.


this is somewhat udosoft  suggested too, but its lost in all the other technical information :)

But i got it from here :

http://www.geocities.com/~budallen/batfiles.html#Exit%20Windows%2098%20Automatically%20Using%20a%20Batch

Comment from georgir
Date: 06/01/2003 10:52AM PDT
Comment

steroyle, instead of just complaining about it bieng confusing, TELL US what is your OS!!! then we can just give you the code that applies to your particular case. until then, we can't answer to your question in a less confusing manner.

Comment from steroyle
Date: 06/01/2003 01:19PM PDT
Author Comment

georgir dont cry, like i said im sorry if im wasting anyones time. I dont spend my life reading these forums!

Thanks udosoft it worked a treat!

Comment from alireza382
Date: 06/13/2004 08:58PM PDT
Comment

I want to write a program in c++ that it can shutdown computer .
HELP ME

Comment from eljakim
Date: 02/18/2005 07:15AM PST
Comment

Just use rundll32.exe shell32.dll,SHExitWindowsEx 8

Comment from adam1213
Date: 05/19/2005 11:07PM PDT
Comment

in a batch file on winxp you can do this with more options!!!!

Such as
remote shutdown - shutdown computers on the network - graphical interface - shutdown /i
timed shutdown   - shutdown /t xx seconds
full list is available in win xp and 2000 by opening cmd and putting in shutdown /?

Comment from plasmatic
Date: 06/13/2005 06:42PM PDT
Comment

here is the easy way:

1. Create a shortcut to C:\WINDOWS\SYSTEM32\SHUTDOWN.EXE
2. Right click the shortcut, then click properties.
3. Add -s to the end of the text in the 'target:' textbox
4. Click ok
5. Run it and the countdown should begin.

you can easily execute this with your application... Look up more on this about how to get rid of the countdown
 

Get your IT Solutions GUARANTEED!
More IT professionals have found their answers instantly at Experts Exchange than at any other IT site
Get Instant Answers    
or ask your specific question to one of our 204K IT experts
ASK AN EXPERT NOW
Programming Channels
Member Login Sign Up
Today!
Login
Password 
Remember Me
Forgot your
Password?
Upgrade to Premium Services
Top 15
Overall
Top 15 Overall Experts Programming
cookre 442704
jaime_olivares 229262
pratap_r 216305
Idle_Mind 214614
Kavar 212693
InteractiveMind 208968
twalgrave 205843
AlexFM 195799
julianH 180713
sunnycoder 171599
Arthur_Wood 165238
bhagyesht 164069
emoreau 147211
JesterToo 115555
Raisor 111933
Hall of Fame
Top 15
Yearly
Top 15 Yearly Experts Programming
InteractiveMind 208968
cookre 145585
Idle_Mind 141229
pratap_r 124995
jaime_olivares 117822
JesterToo 105355
julianH 97611
gecko_au2003 94610
Raisor 94405
AlexFM 90826
nayernaguib 65876
ldbkutty 61930
TheLearnedOne 58979
Arthur_Wood 54002
ghergu 51896
Expert Awards 2004
Ask your Programming Question
it's quick and easy
What is your expert ranking?
Topic Area

Certified Expert
Certified Expert
Your Level
Get Certified Now
Master 50,000
Guru 150,000
Wizard 300,000
Sage 500,000
Genius 1,000,000
Contact Us | Member Agreement | Internet Rank | Privacy Policy | Supporters | Site Map
Copyright © Experts Exchange LLC 2005. All rights reserved.

at:  http://64.233.161.104/search?q=cache:Wh46OCh941wJ:www.experts-exchange.com/Programming/Q_20632389.html

[ Sept. 2005  pcd ]