26

Is it possible to re-assign the Win+L hotkey to another executable/shortcut?

Use-case - I would like to switch off the monitor of my laptop as soon as it is locked. I know of a executable which can lock and turn off the monitor but I do not want to change the way the system is locked (by running the program explicitly or by some other shortcut). It would be best if Win+L can be assigned to this executable.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Mohit
  • 652
  • 2
  • 8
  • 8

6 Answers6

25

You need to set the following registry key to completely disable the Windows locking feature:

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

And restart the computer.

This works on Win7, Win8 and Win10

user3840170
  • 26,597
  • 4
  • 30
  • 62
franc0is
  • 733
  • 9
  • 14
  • This is the correct answer. I had tried this without the "System" key previously which doesn't work. But yes, this one works on Win8, as well as Win7. I've pasted the .reg file contents into a new answer for convenience of all concerned. – Brent Faust Feb 11 '13 at 02:01
  • 2
    You can read more about this, and download a "reg" file ready to import, from here: http://www.howtogeek.com/howto/windows-vista/disableenable-lock-workstation-functionality-windows-l/ – Brad Parks Aug 09 '13 at 12:51
  • I got a very newbee question. Should I save your [HKEY-...] info in a file with .reg suffix, and then execute it? – Zen Oct 12 '14 at 11:07
  • 1
    This answer save my life. – Zen Oct 13 '14 at 02:46
  • 3
    Doesn't this completely disable locking the workstation? – Kyle Strand Jan 15 '15 at 23:38
  • 1
    Keep in mind that this doesn't just disable `win+l`, but locking in its entirety. It will disable lock in `Start > Shutdown`, lock on resume/wake, etc. – dhulihan Jul 07 '15 at 19:35
  • Saving registry immediately works without restart. I tested on Windows 11. – kuboon Jan 11 '22 at 03:47
13

The registry-based solution on its own completely disables locking the system (even via the Start menu).

Here is a method that actually provides a way to lock the computer without the Win-L chord. Locking can either be done via a shortcut on the taskbar or by pressing them in sequence followed by Enter.

First, create a batch file that can toggle system locking and trigger the lock itself; instructions for doing this are taken from a forum post:

  • Create reg-edit files for turning system locking on or off. This is the same as in Brent Foust's answer.

    • In DisableLockWorkstation.reg:

       Windows Registry Editor Version 5.00
       [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
       "DisableLockWorkstation"=dword:00000001
      
    • In EnableLockWorkstation.reg:

        Windows Registry Editor Version 5.00
      
        [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
        "DisableLockWorkstation"=-
      
  • Run the reg-edit script for disabling the system lock.

  • Create a batch file to toggle the feature using the .reg files:

    regedit /S EnableLockWorkstation.reg
    rundll32.exe user32.dll,LockWorkStation
    regedit /S DisableLockWorkstation.reg
    

Now, you can create a shortcut and pin it to the taskbar:

  • Right-click on the batch file and create a shortcut.
  • Right-click on the new shortcut, edit the shortcut properties, and change target to cmd.exe /C "<path>\lock.bat", where <path> is the full path to the lock.bat file.
  • The shortcut should now be pinnable to the taskbar (this is not true prior to manually changing the target); it can be dragged there as normal.
    • (Note that you may also want to change the icon to something like a padlock before pinning the shortcut to the taskbar.)

As mentioned above, once you've completed the above procedure, you should be able to lock the computer using Win, L, Enter in sequence (not as a chord--though see below for a solution using Ctrl-Alt-L as a chord). This is because that sequence is interpreted as follows:

  • Win -- brings up the Start menu, although you don't actually need to wait for it to load
  • L -- searches for the custom lock-script; on my machine, the lock.bat shortcut was always the first L result if it was the only shortcut on my taskbar starting with L. (Verify this before attempting to lock your computer this way!)
  • Enter -- once the search finds an item, it will be launched--i.e. the shortcut will be called, and your computer will lock. You do not need to wait for the search to load; you can quickly press Win, L, Enter in sequence and walk away. The screen will not lock immediately, but it should lock within a few seconds.

Below is a picture of the taskbar shortcut I made (using this icon):

lock.bat taskbar shortcut


EDIT: Using a chord, such as Ctrl-Alt-L

In the comments below, user lub094 suggests a way to assign the shortcut to the chord Ctrl-Alt-L (or whatever shortcut you'd like). I have not taken the time to test this because I've re-enabled the system shortcut, but I assume that it works.

  • Use the built-in shortcut-creation feature to assign the chord:

    enter image description here

  • Place the shortcut itself in the Start Menu folder:

    "C:\Users\ [user_name]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\ [custom_folder]\"
    
phuclv
  • 37,963
  • 15
  • 156
  • 475
Kyle Strand
  • 15,941
  • 8
  • 72
  • 167
  • 1
    This is the correct answer. It shows how the built in hotkey can be disabled and how you can create your own, assigning one for the file shortcut. Just like to add one thing: to be able to execute the new hotkey, you need the shortcut in some system available folder. I think it should be in a folder that's in the system environment variables, such folders are the libraries. – lub094 Oct 24 '15 at 21:39
  • @lub094 Thank you! I've added that information to the answer. – Kyle Strand Oct 26 '15 at 16:38
  • Also for true hotkeys you can use the windows built in feature like this: http://i.imgur.com/T4KYX9k.png?1 – lub094 Oct 28 '15 at 07:46
  • @lub094 Oh, that looks very convenient. Is that new in Windows 8 or 10, or is that available in 7? – Kyle Strand Oct 28 '15 at 14:44
  • It's available in Windows 7 too. – lub094 Oct 29 '15 at 15:33
  • Okay, I've tried assigning Ctl-Alt-L to my shortcut-to-lock.bat as in your example, but that key-combination doesn't appear to actually do anything, even when I've got the shortcut pinned to the taskbar. Any idea what I might be missing? – Kyle Strand Oct 29 '15 at 15:56
  • 1
    To make it work I had to place the shortcut in the Start Menu folder "C:\Users\ [user_name]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\ [custom_folder]\": http://i.imgur.com/3bro1Pi.png. If it doesn't start working right away, I've found that changing the hotkey combination a couple of times fixes it. – lub094 Oct 30 '15 at 17:02
  • @lub094 Thank you. When I get some free time I'll test that out and re-write my answer accordingly. – Kyle Strand Nov 02 '15 at 17:07
  • @lub094 It's been a year and a half since you've made your suggestion and I haven't had any reason to disable the standard Win-L shortcut again, so I've gone ahead and added your contribution to the answer even though I haven't tested it. Thanks again! – Kyle Strand Mar 16 '17 at 18:25
  • 1
    It is worth noting that anyone who needs to make a .reg file needs to have the "Hide extensions for known file types" setting disabled in their file explorer settings. – Shadoninja Apr 27 '17 at 22:47
  • @Shadoninja Thanks! – Kyle Strand Apr 28 '17 at 00:06
13

The Win+L is a system assigned hotkey and there's no option to disable it. This means there's no way for an application to detect it, unless you use a low-level global keyboard hook (WH_KEYBOARD_LL). This works in XP SP3; haven't tested it in Vista though:

LRESULT CALLBACK LowLevelKeyboardProc(int code, WPARAM wparam, LPARAM lparam) {
    KBDLLHOOKSTRUCT& kllhs = *(KBDLLHOOKSTRUCT*)lparam;
    if (code == HC_ACTION) {
        // Test for an 'L' keypress with either Win key down.
        if (wparam == WM_KEYDOWN && kllhs.vkCode == 'L' && 
            (GetAsyncKeyState(VK_LWIN) < 0 || GetAsyncKeyState(VK_RWIN) < 0))
        {
            // Place some code here to do whatever you want.
            // ...

            // Return non-zero to halt message propagation
            // and prevent the Win+L hotkey from getting activated.
            return 1;
        }
    }
    return CallNextHookEx(0, code, wparam, lparam);
}

Note that you need a low-level keyboard hook. A normal keyboard hook (WH_KEYBOARD) won't catch hotkey events.

phuclv
  • 37,963
  • 15
  • 156
  • 475
efotinis
  • 14,565
  • 6
  • 31
  • 36
  • @elmarco, yes, it does work in XP. Maybe Vista/7 have become more strict about letting the system hotkeys get overridden? Also, make sure your DLL is 64-bit if you're trying this in a 64-bit OS. – efotinis May 23 '13 at 16:06
  • my app is 64-bit, on a 64-bit system. It blocks other keys fine, but not win+l – elmarco May 23 '13 at 21:52
  • 2
    You're right. I just tested it on Win7 x64 and it seems that Win+L is handled specially (returning non-0 from the hook doesn't block the Lock Screen). To be honest, I don't blame them for doing this. So, it seems that FrancoisB's suggestion of disabling locking via a policy is the proper way to do this in Win7+ (and perhaps Vista too). – efotinis May 25 '13 at 13:39
3

The @FrancoisB method works for Win8 and Win7. To automate the solution:

  1. Create a text file with the .reg suffix (DisableWinL.reg, for example)

  2. Paste the following content and save the file:

    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
    "DisableLockWorkstation"=dword:00000001
    
  3. Open that file with RegEdit (double-click should work) to execute the change.

    This file can be copied to a new machine to repeat the process. And another one named something like "EnableWinL.reg" could be created that re-enables the Win+L key:

    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
    "DisableLockWorkstation"=dword:00000000
    
phuclv
  • 37,963
  • 15
  • 156
  • 475
Brent Faust
  • 9,103
  • 6
  • 53
  • 57
3

Looks like you can't.

You can disable all built-in Windows hotkeys except Win+L and Win+U by making the following change to the registry (this should work on all OSes but a reboot is probably required):

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer NoWinKeys REG_DWORD 0x00000001 (1)

(http://www.autohotkey.com/docs/misc/Override.htm)

But you could try using Tweak UI. Under the Explorer tree view item, uncheck "Enabled Windows+X" hotkeys. Hoekey also might work, haven't tried it. Source.

ine
  • 14,014
  • 8
  • 55
  • 80
  • Has to do with the fact that this is being registered by Winlogon, not Explorer - so this would be the wrong section to look for settings. A hook can be used to emulate the functionality of registered hotkeys (as mentioned in this topic and elsewhere). – 0xC0000022L Mar 08 '11 at 19:24
  • Why Win+U? Why does Microsoft force accessibility if it is not being used? :roll: – Synetech Mar 20 '11 at 21:52
0

Use power toys for windows 10. There you have options to remap shortcuts.. download power toys

kumarahul
  • 396
  • 4
  • 10