Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

As the title says I want to be able make Windows Media Player Pause when Locking my PC and Play again when I've Unlocked it.

Is this possible?

I did try to do this with this AutoHotKey Script:

;---------------------------------------------------------------
;Notify Lock\Unlock
;   This script monitors LockWorkstation calls
;
;   If a change is detected it 'notifies' the calling script
;      On Lock
;         This script will call function "on_lock()"
;      On Unlock
;         This script will call fucntion "on_unlock()"
;IMPORTANT: The functions "on_lock()" and "on_unlock()" DO NOT
;exist in this script, they are to be created in the script that
;calls notify_lock_unlock() (presumably your main script)
;---------------------------------------------------------------
;Re-purposed by WTO605
;Last edited 2009-08-18 16:34 UTC
;---------------------------------------------------------------
;Based on Winamp_Lock_Pause by MrInferno
;Posted: Fri Apr 21, 2006 4:49 am
;Source: http://www.autohotkey.com/forum/topic9384.html
;---------------------------------------------------------------
;Winamp_Lock_Pause was/is based on script codes from "shimanov"
;Posted: Thu Sep 15, 2005 12:26 am   
;Source: http://www.autohotkey.com/forum/viewtopic.php?t=5359
;Posted: Tue Dec 06, 2005 9:14 pm
;Source: http://www.autohotkey.com/forum/viewtopic.php?t=6755
;---------------------------------------------------------------

;Initialize global constants
WTS_SESSION_LOCK      :=   0x7
WTS_SESSION_UNLOCK      :=   0x8
NOTIFY_FOR_ALL_SESSIONS   :=   1
NOTIFY_FOR_THIS_SESSION   :=   0
WM_WTSSESSION_CHANGE   :=   0x02B1

notify_lock_unlock()
{
   Global WM_WTSSESSION_CHANGE
   Global NOTIFY_FOR_ALL_SESSION

   hw_ahk := FindWindowEx( 0, 0, "AutoHotkey", a_ScriptFullPath " - AutoHotkey v" a_AhkVersion )

   OnMessage( WM_WTSSESSION_CHANGE, "Handle_WTSSESSION_CHANGE" )

   success := DllCall( "wtsapi32.dll\WTSRegisterSessionNotification", "uint", hw_ahk, "uint", NOTIFY_FOR_ALL_SESSIONS )

   if( ErrorLevel OR ! success )
   {
      success := DllCall( "wtsapi32.dll\WTSUnRegisterSessionNotification", "uint", hw_ahk )
      ;If DLL registration fails, wait 20 seconds and try again
      Sleep, 20000
      notify_lock_unlock()
      ;MsgBox, [WTSRegisterSessionNotification] failed: EL = %ErrorLevel%
   }
   return
}

Handle_WTSSESSION_CHANGE( p_w, p_l, p_m, p_hw )
; p_w  = wParam   ;Session state change event
; p_l  = lParam   ;Session ID
; p_m  = Msg   ;WM_WTSSESSION_CHANGE
; p_hw = hWnd   ;Handle to Window
{
   Global WTS_SESSION_LOCK
   Global WTS_SESSION_UNLOCK

   If ( p_w = WTS_SESSION_LOCK )
   {
      on_lock()
   }
   Else If ( p_w = WTS_SESSION_UNLOCK )
   {
      on_unlock()
   }
}

FindWindowEx( p_hw_parent, p_hw_child, p_class, p_title )
{
   return, DllCall( "FindWindowEx", "uint", p_hw_parent, "uint", p_hw_child, "str", p_class, "str", p_title )
}

notify_lock_unlock()
; Calls function "on_lock()" when computer is locked and "on_unlock()" when computer is unlocked

on_lock()
{
   Send, {Media_Play_Pause}
}

on_unlock()
{
   Send, {Media_Play_Pause}
}

which works nicely so long as I am playing something on media player. If it's paused, then it starts playing when I lock my PC.

I can't seem to find any command line options for Windows Media Player to Pause/Play.

Does anyone know how to get this script to work properly? Or if you have a better idea on how to do this, please say.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Try this little program.

For Chris F - It's a program that turns off your monitor, pauses your media player, and puts your IM programs on AFK when you lock your PC.

share|improve this answer
    
Bare links aren't considered that useful. Can you post some more information about this please. –  ChrisF Jul 29 '10 at 16:46
1  
It's a good program, but unfortunately if Media Player is paused, it plays it when I lock and pauses when I unlock... –  Kryten Jul 29 '10 at 17:08
    
Well that's unfortunate...let me check for something else. –  JNK Jul 29 '10 at 17:09
    
According to the dev site for MonitorES, they have ID'd that issue and it's fixed in the next release. I know it doesn't help you now, though. –  JNK Jul 29 '10 at 17:19
    
That's OK. I'll wait until the next release... or I'll download the source and try fix the problem myself –  Kryten Jul 29 '10 at 17:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.