Shutdown Batch
Moderator: DosItHelp
Shutdown Batch
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.
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
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 /?
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
Code: Select all
set /a seconds=10 * 60
Re: Shutdown Batch
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
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:
Hope this helps.
Code: Select all
@echo off
set /a ShutdownTime=%1*60
shutdown -s -t %ShutdownTime%
Hope this helps.
Re: Shutdown Batch
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"
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
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.
-
- Posts: 7
- Joined: 17 Dec 2014 16:45
Re: Shutdown Batch
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
Thanks...
I have created...
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
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.
-
- Posts: 7
- Joined: 17 Dec 2014 16:45
Re: Shutdown Batch
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
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
-
- Posts: 7
- Joined: 17 Dec 2014 16:45
Re: Shutdown Batch
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
local vers global variables.
Hopefully I don't forget again, thanks @foxidrive
Re: Shutdown Batch
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.