1.

Solve : BATCH FILE + sleep command???

Answer»

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 7shutdown
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
Quote from: behzad-007 on August 11, 2011, 02:43:32 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
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?

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.
Quote from: CN-DOS on August 14, 2011, 05:50:31 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


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 "Quote from: CN-DOS on August 14, 2011, 06:12: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.
The sleep command that "behzad-007" gave me (rundll32.exe powrprof.dll,SetSuspendState 0,1,0) hibernates my computer! Is this ment to happen??
Can SOMEONE please help me...the sleep commands I have been given hibernate my computer. I am running Windows 7They haven't been back in 7 years...Quote from: athman8 on April 04, 2018, 07:10:16 AM
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


Discussion

No Comment Found