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?
ProgrammingWindows Batch

Avatar of undefined
Last Comment
eljakim

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
udosoft

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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.
foobar43

windows xp already got it:

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

MellowD0c

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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
MellowD0c

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
georgir

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.
steroyle

ASKER
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!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
alireza382

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

Just use rundll32.exe shell32.dll,SHExitWindowsEx 8
adam1213

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 /?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
plasmatic

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
 
PeterSinger

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?
eljakim

Please post a new question.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.