Computer Hope

Microsoft => Microsoft DOS => Topic started by: lewy on August 10, 2011, 04:05:01 AM

Title: BATCH FILE + sleep command??
Post by: lewy on August 10, 2011, 04:05:01 AM
I have a batch file, and part of it, the user has the choice to either, shutdown, hibernate, logoff or sleep. I have all of the commands except for the sleep command...is there one? I have been un-able to find one
I am using Windows 7
Title: Re: BATCH FILE + sleep command??
Post by: behzad-007 on August 11, 2011, 02:43:32 AM
shutdown
Shutdown.exe -s -t 00

restart
Shutdown.exe -r -t 00

logoff
Shutdown.exe -l

sleep
rundll32.exe powrprof.dll,SetSuspendState 0,1,0

lock
Rundll32.exe User32.dll,LockWorkStation
Title: Re: BATCH FILE + sleep command??
Post by: behzad-007 on August 11, 2011, 02:56:28 AM
@echo off
@echo select number
@echo.
echo 1.shutdown
echo 2.restart
echo 3.logoff
echo 4.sleep
echo 5.lock
@echo.
set/p ch="your choise >"
if %ch%==1 goto shutdown
if %ch%==2 goto restart
if %ch%==3 goto logoff
if %ch%==4 goto sleep
if %ch%==5 goto lock
:shutdown
Shutdown.exe -s -t 00
:restart
Shutdown.exe -r -t 00
:logoff
Shutdown.exe -l
:sleep
rundll32.exe powrprof.dll,SetSuspendState 0,1,0
:lock
Rundll32.exe User32.dll,LockWorkStation
Title: Re: BATCH FILE + sleep command??
Post by: Salmon Trout on August 13, 2011, 05:15:53 AM
That's not how you spell "choice", and what happens after the set /p line if the user just presses ENTER? Or anything other than 1 to 5?

Title: Re: BATCH FILE + sleep command??
Post by: CN-DOS on August 14, 2011, 05:50:31 AM
Hi behzad-007,

Since OP is using Win7 other than XP, I think it's better to use choice command. Because it's complicated to ensue user's legal input when using set /p command.
Title: Re: BATCH FILE + sleep command??
Post by: Salmon Trout on August 14, 2011, 06:01:35 AM
it's complicated to ensue user's legal input when using set /p command.

No it isn't. At least not in this case. The use of quotes around the variables will avoid an error after a null input and a final GOTO after the tests for legal characters can redirect the user to make a further attempt.

Code: [Select]
:loop
set/p ch="Your choice [1,2,3,4 or 5] >"
if "%ch%"=="1" goto shutdown
if "%ch%"=="2" goto restart
if "%ch%"=="3" goto logoff
if "%ch%"=="4" goto sleep
if "%ch%"=="5" goto lock
echo.
echo Enter 1,2,3,4 or 5 only!
echo.
goto loop


Title: Re: BATCH FILE + sleep command??
Post by: CN-DOS on August 14, 2011, 06:12:05 AM
Quote
No it isn't. At least not in this case.

Yes, I agree. We do have method to filter the input. But not your code. Did you tried input only a double quotation mark "
Title: Re: BATCH FILE + sleep command??
Post by: Salmon Trout on August 14, 2011, 06:35:05 AM
Yes, I agree. We do have method to filter the input. But not your code. Did you tried input only a double quotation mark "

That's a good one.
Title: Re: BATCH FILE + sleep command??
Post by: lewy on August 15, 2011, 03:47:13 AM
The sleep command that "behzad-007" gave me (rundll32.exe powrprof.dll,SetSuspendState 0,1,0) hibernates my computer! Is this ment to happen??
Title: Re: BATCH FILE + sleep command??
Post by: lewy on August 31, 2011, 02:49:51 PM
Can someone please help me...the sleep commands I have been given hibernate my computer. I am running Windows 7
Title: Re: BATCH FILE + sleep command??
Post by: patio on April 04, 2018, 09:28:42 AM
They haven't been back in 7 years...
Title: Re: BATCH FILE + sleep command??
Post by: Squashman on April 04, 2018, 12:12:41 PM
I use a batch file to start up a few of the programs I need running in the background. Up until now, I had used the pause command to execute it after some of the other start-ups finished. I would prefer to use the wait or sleep commands but they do not appear to be included in Windows 7.Anybody know how to put those commands back in, or a different method that achieves the same results?
Timeout (https://ss64.com/nt/timeout.html)