Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: BATCH FILE + sleep command??  (Read 16743 times)

0 Members and 1 Guest are viewing this topic.

lewy

    Topic Starter


    Beginner

    • Experience: Experienced
    • OS: Windows 7
    BATCH FILE + sleep command??
    « 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

    behzad-007



      Rookie

      • Experience: Beginner
      • OS: Unknown
      Re: BATCH FILE + sleep command??
      « Reply #1 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
      « Last Edit: August 11, 2011, 03:02:19 AM by behzad-007 »

      behzad-007



        Rookie

        • Experience: Beginner
        • OS: Unknown
        Re: BATCH FILE + sleep command??
        « Reply #2 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

        Salmon Trout

        • Guest
        Re: BATCH FILE + sleep command??
        « Reply #3 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?

        « Last Edit: August 13, 2011, 05:36:07 AM by Salmon Trout »

        CN-DOS



          Rookie

          • Experience: Experienced
          • OS: Windows Vista
          Re: BATCH FILE + sleep command??
          « Reply #4 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.

          Salmon Trout

          • Guest
          Re: BATCH FILE + sleep command??
          « Reply #5 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



          CN-DOS



            Rookie

            • Experience: Experienced
            • OS: Windows Vista
            Re: BATCH FILE + sleep command??
            « Reply #6 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 "

            Salmon Trout

            • Guest
            Re: BATCH FILE + sleep command??
            « Reply #7 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.

            lewy

              Topic Starter


              Beginner

              • Experience: Experienced
              • OS: Windows 7
              Re: BATCH FILE + sleep command??
              « Reply #8 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??

              lewy

                Topic Starter


                Beginner

                • Experience: Experienced
                • OS: Windows 7
                Re: BATCH FILE + sleep command??
                « Reply #9 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

                patio

                • Moderator


                • Genius
                • Maud' Dib
                • Thanked: 1769
                  • Yes
                • Experience: Beginner
                • OS: Windows 7
                Re: BATCH FILE + sleep command??
                « Reply #10 on: April 04, 2018, 09:28:42 AM »
                They haven't been back in 7 years...
                " Anyone who goes to a psychiatrist should have his head examined. "

                Squashman



                  Specialist
                • Thanked: 134
                • Experience: Experienced
                • OS: Other
                Re: BATCH FILE + sleep command??
                « Reply #11 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