Page 1 of 2
Shutdown Batch
Posted: 10 Dec 2014 10:21
by btk
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.
Re: Shutdown Batch
Posted: 10 Dec 2014 10:38
by foxidrive
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 /?
Re: Shutdown Batch
Posted: 10 Dec 2014 11:41
by btk
Example please.
Re: Shutdown Batch
Posted: 10 Dec 2014 11:50
by Squashman
Re: Shutdown Batch
Posted: 10 Dec 2014 19:08
by btk
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?
Re: Shutdown Batch
Posted: 10 Dec 2014 22:32
by ALbino
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.
Re: Shutdown Batch
Posted: 11 Dec 2014 06:10
by btk
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"
Re: Shutdown Batch
Posted: 11 Dec 2014 15:02
by ALbino
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.
Re: Shutdown Batch
Posted: 22 Dec 2014 08:24
by williamt31
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
Re: Shutdown Batch
Posted: 22 Dec 2014 08:48
by btk
Thanks...
I have created...
Code: Select all
@echo off
set /a ShutdownTime=%1*60
IF "%1%"=="off" (
Shutdown -a
) ELSE (
shutdown -s -t %ShutdownTime%
)
Re: Shutdown Batch
Posted: 22 Dec 2014 09:02
by Squashman
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.
Re: Shutdown Batch
Posted: 22 Dec 2014 09:46
by williamt31
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.
Re: Shutdown Batch
Posted: 22 Dec 2014 16:03
by foxidrive
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
Re: Shutdown Batch
Posted: 23 Dec 2014 11:07
by williamt31
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
Re: Shutdown Batch
Posted: 23 Dec 2014 11:30
by foxidrive
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.