1

I'm trying to remap WinLock to something new. Basiclly i want to remove Win+L to lock Windows and add Win+L to Open a specific program to be opened. Any Help ? Thanks.

PS: currently i using #L::Run "C:\Program Files\program.exe" return to open a program but it also lock workstation.i found a way in Registry to disable the function of Win+L to lock Windows but i dont want to edit registry so i'm Curious if that can be done with autohotkey ?

  • 1
    Hi. It would be very helpful to know what you've tried so far. – CLockeWork Mar 10 '14 at 9:52
  • currently i using #L::Run "C:\Program Files\program.exe" return to open a program but it also lock workstation.i found a way in Registry to disable the function of Win+L to lock Windows but i dont want to edit registry so i'm curios if that can be done with autohotkey ? – Sina Moradi Mar 10 '14 at 9:59
  • Cool, if you edit your question to flesh it out with this info you'll be more likely to get an solid answer (plus it'll push your question back up the queue) – CLockeWork Mar 10 '14 at 10:07
4

AHK can't intercept these Windows shortcuts. If you don't want to edit registry values, I don't think there is a way to do this. The registry value is HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System: DisableLockWorkstation which if 1 will disallow locking the system entirely, with or without shortcut, and with 0 locking is allowed and shortcut Win+L will lock the system no matter what tries to intercept it. Commented (for those looking for a working Win+L solution but don't know AHK) code:

With registry editing:

  ; WARNING: Programs that use User32\LockWorkStation (i.e. programmatically locking the operating system) may not work correctly! 
  ; This includes Windows itself (i.e. using start menu or task manager to lock will also not work).
  ; Script changes Win-L to show a msgbox and Ctrl-Alt-L to lock windows

  ; The following 3 code lines are auto-executed upon script run, the return line marks an end to the auto-executed code section.
  ; Register user defined subroutine 'OnExitSub' to be executed when this script is terminating
  OnExit, OnExitSub

  ; Disable LockWorkStation, so Windows doesn't intercept Win+L and this script can act on that key combination 
  SetDisableLockWorkstationRegKeyValue( 1 )
return

#l::
  MsgBox, Win-L was pressed! ; Arbitrary code here
return

^!l::
  ; Ctrl-Alt-L 
  ; Temporary enable locking
  SetDisableLockWorkstationRegKeyValue( 0 )
  ; Lock
  DllCall( "User32\LockWorkStation" )
  ; Disable locking again 
  SetDisableLockWorkstationRegKeyValue( 1 )
return

OnExitSub:
  ; Enable LockWorkStation, because this script is ending (so other applications aren't further disturbed)
  SetDisableLockWorkstationRegKeyValue( 0 )
  ExitApp
return

SetDisableLockWorkstationRegKeyValue( value )
  {
  RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, %value%
  }
  • I've basically used the same technique to intercept WIN + L in order to forward incoming Lync calls to my mobile phone at work when I'm not at my PC. I haven't found any way to do this except manipulating the registry. You may want to add that if DisableLockWorkstation is set to true, there is no way to lock the workstation, even the respective buttons from the start menu or the "Ctrl+Alt+Del Screen" will just do nothing. – MCL Mar 23 '14 at 17:11
  • I like your solution, but for me it does not work. Possibly because I'm working in a corporate environment, and I'm not sure what policies are applied to programs trying to access the registry. Is there a way to get feedback from AHK when the RegWrite fails? – Ward Feb 3 '16 at 14:38
  • @WardC "ErrorLevel is set to 1 if there was a problem or 0 otherwise. A_LastError is set to the result of the operating system's GetLastError() function.", taken from help for RegWrite – hippibruder Feb 3 '16 at 15:18
  • @0fnt In an AHK script the beginning is called auto-execute section and is executed once when the script starts. I have also added some comments. – hippibruder Apr 26 '16 at 13:36
  • @hippibruder Thank you! So what's the diff between the initial and final OnExitSub? Looks to me that the first thing should be OnEnterSub or something like that? – 0fnt Apr 27 '16 at 3:43

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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