Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Wanna override Win + L?


  • Please log in to reply
2 replies to this topic
jmkangkr
  • Members
  • 5 posts
  • Last active: Aug 22 2013 08:05 AM
  • Joined: 26 Jul 2013

Hi folks.

 

    WIN + L locks the machine and this is a special Windows shortcut that cannot be overridden. The only way to override WIN + L is to disable Windows lock feature. But, once you disable this feature, there's no way to lock your machine with any method. Therefore, to override WIN + L while keeping Windows Lock feature, we need to dynamically turn on & off this feature.

 

    First, you need to create .reg files to disable and enable Windows Lock feature.

 

<DisableLockWorkstation.reg> 

Windows Registry Editor Version 5.00


[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
"DisableLockWorkstation"=dword:00000001

<EnableLockWorkstation.reg>

Windows Registry Editor Version 5.00


[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
"DisableLockWorkstation"=-

Then, create a lock.bat file like below

regedit /S EnableLockWorkstation.reg
rundll32.exe user32.dll,LockWorkStation
regedit /S DisableLockWorkstation.reg
Run DisableLockWorkstation.reg once. You will remove Windows Lock feature. However, lock.bat will still lock your machine because it will turn on the feature right before executing locking (then, turn it off again).
 
Now, you can use WIN + L shortcut in your script to lock your machine or to do some app specific action. This is my use case
 
[snip]
; Lock the machine
#l::
Run "C:\Users\viciousmonkey\Documents\AutoHotKeyScripts\lock.bat"
return

[snip]
; Move the focus to file list pane in Explorer
#IfWinActive ahk_class CabinetWClass
#l::
    ControlFocus, DirectUIHWND3, A
    SendInput, {Space}
    return
#IfWinActive
Thanks!


gwarble
  • Members
  • 624 posts
  • Last active: Aug 12 2016 07:49 PM
  • Joined: 23 May 2009
Good idea, now for homework you should write the solution completely in ahk and you wont need any bat or reg files

Hint: RegWrite/read

dinoxor
  • Members
  • 1 posts
  • Last active: Mar 25 2014 08:45 PM
  • Joined: 21 Mar 2014

Good idea, now for homework you should write the solution completely in ahk and you wont need any bat or reg files

Hint: RegWrite/read

 
It took me forever to find out why my script isn't working but I finally figured it out.

#Warn All, Off
PAUSE:: 
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 0
	DllCall("LockWorkStation")
	sleep, 1000
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 1
	
return

The sleep script is a MUST or it'll just run all three commands at once which will cause the DisableLockWorkstation to quickly changes back to 1 before it has a chance to lock your workstation.