Computer Hope
Microsoft => Microsoft DOS => Topic started 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
-
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
-
@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.
-
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.
: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
-
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 "
-
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 7
-
They haven't been back in 7 years...
-
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)