Link to home
Start Free TrialLog in
Avatar of steroyle
steroyle

asked on

Shutdown using a .BAT file?

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?
ASKER CERTIFIED SOLUTION
Avatar of udosoft
udosoft
Flag of Germany 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
Avatar of steroyle
steroyle

ASKER

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.
windows xp already got it:

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

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.
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
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.
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!
I want to write a program in c++ that it can shutdown computer .
HELP ME
Just use rundll32.exe shell32.dll,SHExitWindowsEx 8
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 /?
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
 
I want to use shutdown.exe (or something else) to shutdown a remote w3k server from a batch file, but I do not want the batch file to return (keep running) till the remote machine has compleated its shutdown.  Once the shutdown has finished, the batch file cna continue to run.

Any sugestions?
Please post a new question.