Announcement

Collapse
No announcement yet.

logoff user & go to sleep

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • logoff user & go to sleep

    is there a way to script a user log off and then go to sleep (delayed?)
    I'd like a one-click solution to log off the current user (windows 7 pro) and that the computer will go to sleep.

    ie. a delayed shutdown.exe with the LogOff command won't work because the /l (or -l) switch can't be used with the /t (or -t) switch for delay.

    REM Log OFF
    %windir%\system32\shutdown.exe -l -f
    REM Go to Sleep
    %windir%\System32\rundll32.exe powrprof.dll,SetSuspendState 0,1,0

    This won't work in a script because the system will fall asleep first, if you wake-up the system again THEN it'll Log Off.

  • #2
    Re: logoff user & go to sleep

    Originally posted by APOC View Post
    is there a way to script a user log off and then go to sleep (delayed?)
    Nope you can't accomplish this with just one script. The command shutdown.exe -l -f will logoff the user. When the user is logged off the running script (executed by the user) is killed = before it is time you want the 'go to sleep' command to run.


    Maybe you can try a scheduled task for bringing the computer to sleep. A task that is triggerd to run every time a user has logged off.
    (trigger: On an Event / Log is: System / Source is: Winlogon / event ID is: 7002 / delay task for: 30 seconds. General: run the task with the following account: <admin name> / Run whether user is logged on or not)
    When triggered it starts a batch.
    i.e.;
    Code:
    @echo off
    
    >NUL 2>&1 call:chkforproc wuaudt.exe
    
    start %windir%\System32\RUNDLL32.EXE powrprof.dll,SetSuspendState 0,1,0
    
    GOTO:EOF
    
    :chkforproc
    Set /a n+=1
    timeout.exe /t 1 /nobreak
    If %n% gtr 5 (EXIT)
    (Tasklist.exe /FI "IMAGENAME eq %*" /NH | findstr.exe /N /IC:"%*")&&(
      timeout.exe /t 4 /nobreak
      goto :chkforproc
     )
    exit /b 0
    You still have to test it if it works well in all circumstances. I would recommend to use the delays applied in the task and the script.

    /Rems
    Last edited by Rems; 23rd April 2014, 20:09.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: logoff user &amp; go to sleep

      You still have to test it if it works well in all circumstances
      Thanks, Rems!!
      This solution working perfectly on Windows 7 Ent/Pro. I'm also searched for something similar...
      Just one remark... If in the system power plan enabled hibernation, the command SetSuspendState 0,1,0
      will cause computer hibernate instead of sleep. In order to force it sleep after log off, hibernation should be turned off. Reference:
      http://msdn.microsoft.com/en-us/library/aa373201.aspx
      Alternatively it is possible to use NirCmd.exe tool for forcing computer to go into standby mode even when hibernation is enabled:
      http://www.nirsoft.net/utils/nircmd.html
      Last edited by igor7; 15th April 2014, 15:52.

      Comment


      • #4
        Re: logoff user &amp; go to sleep

        ( I already disabled Hibernate, you can do this easily with: powercfg -h off )

        @Rems:
        Great Workaround, still a slight problem for my situation though...
        Now the system always goes to sleep when a user log's off, this is almost what I want and need.

        Situation:
        I use a big-screen for Narrowcasting, when the system is 'logged off' a default screen saver shows all our important projects (also when a user is 'logged on' the same screen saver is enabled by default).
        SO I don't always want the computer set to standby/sleep when a user does log-off (the system is also being used for presentations by multiple users).
        BUT sometimes a user specifically wants it to go to sleep when there are people in the room and the big-screen is only distracting, I know one can just turn off the screen, but putting the whole system a sleep is energy wise a better/smarter solution imo.

        It's really needed on demand somehow, hoping to find some way to make this work. I'll keep searching for a possible working combination with your directions, really appreciate your example for a possible direction.
        PS. Some thoughts: maybe call/run/start a (delayed) schedule for sleep from batch in combination with log-off

        I hope I sketched out the situation clear enough?
        Last edited by APOC; 16th April 2014, 10:54. Reason: added PS.

        Comment


        • #5
          Re: logoff user &amp; go to sleep

          Maybe something like,
          The logoff batch adds some folder or other entry (user must have write permissions) with an unusual name before it logs off the user.

          The batch lauched by the task scheduler check if the folder exist. If it exist it deletes the folder then do the rest of the commands and the computer go to sleep. If the folder didn't exist the batch does not continue.


          /Rems

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment


          • #6
            Re: logoff user &amp; go to sleep

            Originally posted by igor7 View Post
            Thanks, Rems!!
            This solution working perfectly on Windows 7 Ent/Pro. I'm also searched for something similar...
            Just one remark... If in the system power plan enabled hibernation, the command SetSuspendState 0,1,0
            will cause computer hibernate instead of sleep. In order to force it sleep after log off, hibernation should be turned off. Reference:
            http://msdn.microsoft.com/en-us/library/aa373201.aspx
            Alternatively it is possible to use NirCmd.exe tool for forcing computer to go into standby mode even when hibernation is enabled:
            http://www.nirsoft.net/utils/nircmd.html
            Thank you igor7 for the additional information.

            /Rems

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: logoff user &amp; go to sleep

              If have modified the ":chkforproc" subroutine a bit, Goto:EOF is replaced by EXIT

              The goto:EOF command ends the subroutine and return back to the point from where the subroutine was called. That is not desired because the script should be ended at that point.

              The reason why I added the subroutine is because when a user shutdown the computer, s/he will be logged of first (this triggers the task) before the computer shutdown. And when the shutdown takes longer than usual, i.e. when it is installing updates, the computer goes to sleep while wuaudt.exe is running.


              /Rems
              Last edited by Rems; 23rd April 2014, 20:11.

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment

              Working...
              X