Shut down computer on exit

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Mel0nparty
Posts: 4
Joined: 16 Oct 2012 23:20

Shut down computer on exit

#1 Post by Mel0nparty » 16 Oct 2012 23:25

Hi

How can I make a BATCH file that when cmd is exited the computer will shut down

if its not possible can some one tell me how i could do that with another program

Thanks :D

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Shut down computer on exit

#2 Post by foxidrive » 17 Oct 2012 04:58

You can use a child shell and run shutdown in the parent shell.
People can close the CMD session with the mouse, hence it won't work.

Why do you want to do this? Is this for your own computer?
You can also use a batch file to call shutdown directly.

miskox
Posts: 668
Joined: 28 Jun 2010 03:46

Re: Shut down computer on exit

#3 Post by miskox » 17 Oct 2012 13:56

The last line in your .cmd should be:

Code: Select all

shutdown -s -t 0


Saso

Mel0nparty
Posts: 4
Joined: 16 Oct 2012 23:20

Re: Shut down computer on exit

#4 Post by Mel0nparty » 17 Oct 2012 23:22

i wish to make a last defence for my computer just in case someone finds out my password, i would put the BATCH file in the start up and when they login to my computer the cmd window will come up asking for a second password is they get it incorrect 3 times it will shut down and if they exit the cmd the computer will shut down

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Shut down computer on exit

#5 Post by Liviu » 17 Oct 2012 23:37

Mel0nparty wrote:i wish to make a last defence for my computer ...

That can only work provided that the user does not:
- find out your second password as well;
- close the cmd window, or press Ctrl-C or Ctrl-Break, or kill cmd.exe from task manager;
- simply ignore the cmd window, perhaps minimize it, then go about their business;
- run notepad, open the .cmd file and find out what you check the password against, then type in that uber secret second password.

In other words, forget about it. Can't work, won't work, least of all in a batch file.

Mel0nparty
Posts: 4
Joined: 16 Oct 2012 23:20

Re: Shut down computer on exit

#6 Post by Mel0nparty » 18 Oct 2012 02:46

is there a way of doing this with a different program?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Shut down computer on exit

#7 Post by foxidrive » 18 Oct 2012 02:50

Whole drive encryption might work that way. It will require a password to access the drive I think.

http://www.truecrypt.org/

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Shut down computer on exit

#8 Post by abc0502 » 18 Oct 2012 08:52

If you want a trick, you can do this, make a batch and add these lines to it

Code: Select all

@Echo off
shutdown -s -f -t 0

and put it in the start up folder in the start menu.

The trick is when you log-in, after you enter your password and press enter, press left shift key and keep pressing it till the computer become ready , this will disable any application in the start up folder from running and that way the batch won't work and the computer won't shutdown.

if any one else opened your computer and logged in, he don't know about the batch and the pressing of the left shift key, so the shutdown will happen and he won't even be able to get to the run menu and write

Code: Select all

shutdown -a
to disable the shutdown :wink:

but make sure you disable the sticky key from the Accessibility Options in the control panel
and if you forgot about it, you will keep shutting down, test it first and replace the 0 after -t with 1000 seconds to test to see it this idea work for you then return the 0 back or add any time you want. 8)

Boombox
Posts: 80
Joined: 18 Oct 2012 05:51

Re: Shut down computer on exit

#9 Post by Boombox » 18 Oct 2012 09:10

You will need a 'timer' in another cmd window.

Create a batch file called Alpha.bat containing;

Code: Select all

wscript.exe "%cd%\hide.vbs" "Alpha.bat"
start Omega.bat
timeout /t 10>nul
shutdown -s -f -t 0


(Omega.bat will be your password request app.)

When the correct password is entered, Omega.bat should close Alpha.bat

Create a .vbs file called 'hide.vbs' (can be done with notepad)

Enter the code below and save...

Code: Select all

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False


Using the vb script. The 1st bat is hidden and calls the 2nd bat to request a password.

If after 10 seconds, no one has entered the correct password. The computer shuts down.
Last edited by Boombox on 18 Oct 2012 09:24, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Shut down computer on exit

#10 Post by foxidrive » 18 Oct 2012 09:13

abc0502 wrote:If you want a trick, you can do this, make a batch and add these lines to it

Code: Select all

@Echo off
shutdown -s -f -t 0

and put it in the start up folder in the start menu.

The trick is when you log-in, after you enter your password and press enter, press left shift key and keep pressing it till the computer become ready , this will disable any application in the start up folder from running and that way the batch won't work and the computer won't shutdown.

if any one else opened your computer and logged in, he don't know about the batch and the pressing of the left shift key, so the shutdown will happen and he won't even be able to get to the run menu and write

Code: Select all

shutdown -a
to disable the shutdown :wink:


That sounds like quite an effective tip. :)

One issue is that it will also disable all the other programs in the startup group. But it's sneaky - I like it. :)

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Shut down computer on exit

#11 Post by abc0502 » 18 Oct 2012 09:27

@Foxidrive, thanks :)
and thanks for pointing at this problem, i don't usually use start up folder, but if he has programs in the start up folder he can use the registry instead, it can solve this problem.

Mel0nparty
Posts: 4
Joined: 16 Oct 2012 23:20

Re: Shut down computer on exit

#12 Post by Mel0nparty » 18 Oct 2012 17:05

Thanks @foxdrive @abd0502 and @Boombox
i'll try all of the suggestions and tell you which one was the best :D

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Shut down computer on exit

#13 Post by Liviu » 18 Oct 2012 21:52

@abc0502 & @Boombox, those are clever tricks. They might well work if you wanted to protect against grandpa incidentally snooping. But they won't work against someone with even basic knowledge of Windows. One can always reboot into safe mode and bypass startup programs entirely, or ^C like mad during a regular boot, or use that 10 seconds grace period to kill or suspend any cmd.exe, hidden or not. The OP hasn't given much context, so I won't comment on that. But in the general case, I stand by what I said earlier - it's simply not possible to add any "last defense" barrier with a startup program. Technically impossible with a batch, practically impossible with any kind of program short of sophisticated virus/worm-bordering hacks.

Boombox
Posts: 80
Joined: 18 Oct 2012 05:51

Re: Shut down computer on exit

#14 Post by Boombox » 19 Oct 2012 05:18

------------------------
That's nice Liviu, you got anything constructive to say?... Any cool tricks you could offer?
------------------------

Just like with any system... This one piece of security (your batch file) should never be your only defense.

Create whatever batch file you see fit and use it happily :)

Fill it with all the colourful DOS language you know and can find. And rest knowing that you've done your best with it all...
...AND PRACTICE IT! You may decide against the whole .bat idea later... But that's up to you :)

Convert your .bat to an .exe to hide it's workings
Run a seperate Hidden CMD window that kills any opened taskmanager.exe's (for intruders unaware of rapid ^C use)
If you have XP, ^C can be disabled via batch, (at CMD type Break off)
Use Visual Basic Script (Excellent, powerful accompaniment to batch)

Add BIOS Boot Password
Disable Booting from External Devices
Encrypt drive with some software...
Disable Keyboard with Keyboard Lockers requiring specific mouse bahaviours on login
Use a restricted account for daily work, and admin for safe mode & maintenance
NOSAFEMODE is a purchasable piece of software to hide Safe mode in win 7

Above all, enjoy your batch programming.

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Shut down computer on exit

#15 Post by Liviu » 19 Oct 2012 12:14

Boombox wrote:That's nice Liviu, you got anything constructive to say?

Thank you for the entertaining, borderly poetic, followup ;-)

My very constructive advice for anyone concerned about security remains: forget about batch files and startup group tricks. Nothing done there can come even close to the built-in Windows authentication. If one is worried of break-ins, use a stronger password and hide it well.

On the other hand, if all one is looking for is a fuzzy warm illusion of "last defense" security then by all means go ahead and throw a batch file in startup.

Liviu

Post Reply