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 ?

3
  • 2
    Hi. It would be very helpful to know what you've tried so far.
    – CLockeWork
    Mar 10, 2014 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 ? Mar 10, 2014 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, 2014 at 10:07

1 Answer 1

7

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%
  }
9
  • 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, 2014 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, 2016 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 Feb 3, 2016 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. Apr 26, 2016 at 13:36
  • 1
    This syntax of RegWrite has been deprecated, see autohotkey.com/docs/commands/RegWrite.htm for more.
    – Ynjxsjmh
    Mar 19, 2020 at 9:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .