Shutdown Batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
btk
Posts: 13
Joined: 17 Apr 2014 21:51

Shutdown Batch

#1 Post by btk » 10 Dec 2014 10:21

I am in doubt.
I want to develop a batch when I enter the time in minutes and the same
multiply by 60 and set the shutdown command.

Ex .: off.bat 10
Within the batch he take the value 10 multiply by 60 and add the command
Shutdown -s -t * value *

As is known, the shutdown command only accepts value in seconds and my input would be in minutes.

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

Re: Shutdown Batch

#2 Post by foxidrive » 10 Dec 2014 10:38

Have you tried to solve this by yourself?

It uses the set /a variation of the set command.

You can get help from typing this at the cmd prompt set /?

btk
Posts: 13
Joined: 17 Apr 2014 21:51

Re: Shutdown Batch

#3 Post by btk » 10 Dec 2014 11:41

Example please.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Shutdown Batch

#4 Post by Squashman » 10 Dec 2014 11:50

Code: Select all

 set /a seconds=10 * 60

btk
Posts: 13
Joined: 17 Apr 2014 21:51

Re: Shutdown Batch

#5 Post by btk » 10 Dec 2014 19:08

Code: Select all

@echo off
set /a time=%1*60
shutdown -s -t time


saved the file as "off.bat"
I go to the prompt and typed: off 10
However this is not happening at all.

Runs the help menu shutdown command.

where is the error?

ALbino
Posts: 29
Joined: 23 Oct 2014 19:27

Re: Shutdown Batch

#6 Post by ALbino » 10 Dec 2014 22:32

You need to make time into a variable by putting %'s around it. However, %Time% is an already defined Windows variable, so you should probably call it something ShutdownTime:

Code: Select all

@echo off
set /a ShutdownTime=%1*60
shutdown -s -t %ShutdownTime%


Hope this helps.

btk
Posts: 13
Joined: 17 Apr 2014 21:51

Re: Shutdown Batch

#7 Post by btk » 11 Dec 2014 06:10

Thank you very much.

Now I want to increase the code.

For the parameter I want to cancel the shutdown command.
Ex. "Off.bat off" instead of using a number write "off" and
he run the "Shutdown -a"

ALbino
Posts: 29
Joined: 23 Oct 2014 19:27

Re: Shutdown Batch

#8 Post by ALbino » 11 Dec 2014 15:02

You don't even need to type "off" if you're going to just have a separate file named off.bat:

Code: Select all

@echo off

shutdown -a
echo Shutdown was canceled.

williamt31
Posts: 7
Joined: 17 Dec 2014 16:45

Re: Shutdown Batch

#9 Post by williamt31 » 22 Dec 2014 08:24

For the parameter I want to cancel the shutdown command.
Ex. "Off.bat off" instead of using a number write "off" and
he run the "Shutdown -a"


Code: Select all

@ECHO OFF
IF %1 EQU can (
ECHO Cancelling shutdown
shutdown /a
GOTO END
) ELSE (
set ShutdownTime=%1*60
shutdown /s /t %ShutdownTime%
)
:END


Mind if I add my 2 cents? (or 10 lines however you look at it.)
You can either run off 60 or off can (60 or whatever time you need)

Only because I'm having fun playing with if / else blocks now :D

btk
Posts: 13
Joined: 17 Apr 2014 21:51

Re: Shutdown Batch

#10 Post by btk » 22 Dec 2014 08:48

Thanks...

I have created...

Code: Select all

@echo off
set /a ShutdownTime=%1*60

IF "%1%"=="off" (
   Shutdown -a
) ELSE (
   shutdown -s -t %ShutdownTime%
)


Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Shutdown Batch

#11 Post by Squashman » 22 Dec 2014 09:02

btk wrote:Thanks...

I have created...

Code: Select all

@echo off
set /a ShutdownTime=%1*60

IF "%1%"=="off" (
   Shutdown -a
) ELSE (
   shutdown -s -t %ShutdownTime%
)


There should not be a trailing percent with the command line argument.

williamt31
Posts: 7
Joined: 17 Dec 2014 16:45

Re: Shutdown Batch

#12 Post by williamt31 » 22 Dec 2014 09:46

Ya'know it's really annoying, I swear what I wrote was working before I posted it and I went to play with the 'timeout' command (I thought it would give a nice to give a countdown timer) and now I can't get my code to work. :oops:

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

Re: Shutdown Batch

#13 Post by foxidrive » 22 Dec 2014 16:03

williamt31 wrote:Ya'know it's really annoying, I swear what I wrote was working before I posted it



Move this to the top after echo off

Code: Select all

set ShutdownTime=%1*60

williamt31
Posts: 7
Joined: 17 Dec 2014 16:45

Re: Shutdown Batch

#14 Post by williamt31 » 23 Dec 2014 11:07

Ok so I forgot two things, the '/a' on the set and variable 101 (after a shutdown) :/
local vers global variables.

Hopefully I don't forget again, thanks @foxidrive

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

Re: Shutdown Batch

#15 Post by foxidrive » 23 Dec 2014 11:30

williamt31 wrote:Ok so I forgot two things, the '/a' on the set and variable 101 (after a shutdown) :/
local vers global variables.

Hopefully I don't forget again, thanks @foxidrive


No worries, and it just goes to show that none of us win all the time - as I missed the lack of /a too
AND I missed btk and Squashman's post showing the variable.

I must have been on my 5th bottle of beer at that time. ;)

Post Reply