The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    Sleep on lid close Except when...

    Discussion in 'Windows OS and Software' started by Pyro87, Jul 24, 2011.

  1. Pyro87

    Pyro87 Notebook Enthusiast

    Reputations:
    0
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    5
    hello, I am looking for a way to set up my laptop to do the following:

    on battery:
    always sleep on lid close no matter what. (easy)

    on AC power:
    always sleep on lid close unless uTorrent is running (or just when it is downloading)


    I have tried setting uTorrent settings to prevent standby if there are active torrents but that doesn't prevent sleep on lid close.
     
  2. JOSEA

    JOSEA NONE

    Reputations:
    4,013
    Messages:
    3,521
    Likes Received:
    170
    Trophy Points:
    131
  3. Falco152

    Falco152 Notebook Demon

    Reputations:
    442
    Messages:
    1,882
    Likes Received:
    75
    Trophy Points:
    66
    If you are running either Vista/ W7

    Go to power option -> Click Choose what closing lid does -> Change Battery to Sleep, AC to Never

    Change Utorrent Settings, Sleep After Downloading.



    It is odd that utorrent didn't block the standby while downloading.

    Try asking on the utorrent forum for support. You might get a better response than here.
     
  4. Pyro87

    Pyro87 Notebook Enthusiast

    Reputations:
    0
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    5
    is there an option to not have the window open all the time?


    that setting would half work. the problem is i want to sleep the laptop when utorrent is not running. if on ac and not downloading, with those settings it would never sleep.
     
  5. Pyro87

    Pyro87 Notebook Enthusiast

    Reputations:
    0
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    5
    i ended up using autoit and made a script to do what i wanted.


    if any of you use autoit and want this here is the script.

    Code:
    Opt("TrayIconHide", 1)
    
    Global Const $WM_POWERBROADCAST = 0x0218
    ; GUID_LIDSWITCH_STATE_CHANGE GUID
    ; 0xBA3E0F4D, 0xB817, 0x4094, 0xA2, 0xD1, 0xD5, 0x63, 0x79, 0xE6, 0xA0, 0xF3
    Global Const $GUID_LIDSWITCH_STATE_CHANGE = DllStructCreate("byte[16]")
    DllStructSetData($GUID_LIDSWITCH_STATE_CHANGE, 1, Binary("0x4D0F3EBA17B89440A2D1D56379E6A0F3"))
    
    ; create gui and register notification
    Global $GUI = GUICreate("")
    GUIRegisterMsg($WM_POWERBROADCAST, "__WM_POWER")
    Global $hPower = DllCall("user32.dll", "handle", "RegisterPowerSettingNotification", "handle", $GUI, "ptr", DllStructGetPtr($GUID_LIDSWITCH_STATE_CHANGE), "dword", 0)
    ;GUISetState(@SW_HIDE)
    
    Do
    Until GUIGetMsg() = -3
    
    ; unregister notification
    DllCall("user32.dll", "bool", "UnregisterPowerSettingNotification", "handle", $hPower[0])
    
    Func __WM_POWER($hwnd, $msg, $wparam, $lparam)
        #forceref $hwnd
        Local Const $PBT_POWERSETTINGCHANGE = 0x8013
        ; Data member is variable depending on notification
        ; the size of the Data member is returned in DataLength
        Local Const $POWERBROADCAST_SETTING = "byte[16];dword DataLength;byte Data"
    
        Switch $msg
            Case $WM_POWERBROADCAST
                Switch $wparam
                    Case $PBT_POWERSETTINGCHANGE
                        Local $PBT_PSC = DllStructCreate($POWERBROADCAST_SETTING, $lparam)
                        ; GUID of registered notification is the first member of the structure
                        Switch DllStructGetData($PBT_PSC, 1)
                            Case DllStructGetData($GUID_LIDSWITCH_STATE_CHANGE, 1)
                                ; for this notification, Data is an int representing the lid state
                                Local $data = DllStructCreate("int", DllStructGetPtr($PBT_PSC, "Data"))
                                _LidStateChange(DllStructGetData($data, 1))
                                ;
                                Return 1
                        EndSwitch
                EndSwitch
        EndSwitch
    
        Return "GUI_RUNDEFMSG"
    EndFunc
    
    Func _LidStateChange($iState)
        Static $iPrevious = -1
        If $iPrevious = -1 Then
            ; first fire, current state
            $iPrevious = $iState
            Return
        ElseIf $iPrevious = $iState Then
            Return
        Else
            $iPrevious = $iState
        EndIf
        ; lid state:
        ; 0 -> closed
        ; 1 -> open
        Switch $iState
            Case 0
                ConsoleWrite("lid closed" & @CRLF)
                If NOT ProcessExists("uTorrent.exe") Then
                Shutdown(32) ;standby
    			Endif
    			If ProcessExists("uTorrent.exe") Then
                DllCall("user32.dll", "bool", "LockWorkStation")
    			Endif
            Case 1
                ConsoleWrite("lid opened" & @CRLF)
        EndSwitch
    EndFunc