Windows 10: How to Lock (not sleep) laptop on lid close?

23

4

If my laptop is plugged in I want closing the lid to automatically lock the computer, without putting it to sleep. I don't see an option to do this in Power Options:

Power screen

Is there a hack to achieve this?

feetwet

Posted 2019-04-12T16:57:48.997

Reputation: 557

6This is generally a bad idea: your laptop dissipates a good deal of heat through the keyboard, and if you leave the computer running with the lid closed, you risk overheating things. – Mark – 2019-04-12T21:23:25.137

17@Mark: ...and yet you can set it to keep running full blast when you close the lid, without frying anything. – Sean – 2019-04-13T03:26:56.777

Answers

21

As far as I know, there is no built-in function to achieve this. But you can do this using a third party tool.

One of them is LapLock. This program is a lightweight (<50KB), open source tool and it's developed by Etienne Dechamps.

Steps...

  1. Download the program - https://github.com/dechamps/laplock/releases
    (Download the latest laplock.exe release)

  2. Open the Windows Startup folder by using this run command - 'shell:common startup'

  3. Add laplock.exe to your Startup folder.

You can also use Lid Lock to do this.

DxTx

Posted 2019-04-12T16:57:48.997

Reputation: 762

thanks, this implementation pretty much sums up the answer by mazunki, uses GUID_LIDSWITCH_STATE_CHANGE – kevinf – 2019-12-05T00:57:49.203

18

Set "Do Nothing", lock your laptop using Windows key+L, and then you can close the lid.

saidi_amine

Posted 2019-04-12T16:57:48.997

Reputation: 253

16This is the most practical solution. I am always suspicious of any software that chooses to customize something which Windows has built in. I'm looking at you pre-installed "WiFi Booster/manager" crapware! – MonkeyZeus – 2019-04-12T19:09:48.327

1It would seem this should be something you can configure in the registry (if not, Microsoft should make it so). – Jonathan – 2019-04-12T20:40:01.750

16OP: I want closing the lid to automatically lock the computer so this doesn't answer the question. – Agent_L – 2019-04-13T15:39:14.710

6Please do NOT upvote an answer without reading it carefully. This does NOT answer the question and should be DOWN voted (and I would be willing to bet the OP knows he can manually lock his computer before closing the lid) . The site's value diminishes for everyone if we push non-answers to the top by upvoting them. – Jon Bentley – 2019-04-14T17:16:11.397

3I'm downvoting this answer because it does not answer the question "how to automatically lock the computer" – BurnsBA – 2019-04-15T01:35:02.967

@Jon Bentley I think this answer is totally within the bounds of how you should answer questions on this website. From the superuser help page: "Read the question carefully. What, specifically, is the question asking for? Make sure your answer provides that – or a viable alternative. The answer can be “don’t do that”, but it should also include “try this instead”." – findusl – 2019-04-15T07:17:27.153

1I agree that this would be an easy solution if OP needs this for themselves. But what if OP wants to enforce this on laptops belonging to their company or for their grandma etc. In that case this answer is not a solution. – Tvde1 – 2019-04-15T09:36:22.910

@findusl In this particular case, the OP's primary goal is to automatically have the laptop lock when the lid is closed. Proposing a solution that involves a manual step is not a viable alternative - it's something else entirely. I'm sure the OP knows full well that he can do whatever he likes (suspend, turn off, lock, format his hard drive, etc.) manually before closing the lid. It's obvious that such an answer won't fulfil his needs. You said it yourself - "What, specifically, is the question asking for?". Here, it is specifically asking for an automatic solution. – Jon Bentley – 2019-04-15T18:25:29.740

@Jon Bentley that is only true if you know that op knows about the win+l command. I myself didn't know about it and I bet you I can find easily people who don't. Nobody learns all the shortcuts by heart. And this is the closest solution to locking without sleep on close you can get without extra tools or scripts. You should read about the XY problem, a problem that comes up very often on stackoverflow (where I'm more active) and for sure here too. Such answers have often enough helped me when I found them, I'm sure this one helps someone too. – findusl – 2019-04-15T20:39:04.360

@findusl You don't need to know about the win+L shortcut to be able to lock the screen manually. This is most definitely not an XY problem. An XY problem is when someone asks the wrong question because they don't realise what the real solution is (e.g. "What type of hammer should I use to smash my hard drive to bits?" when really they just want to know how to erase their data). It's obvious in this case that the OP does in fact want the screen to lock when he closes the lid, and that he hasn't simply misunderstood his problem. – Jon Bentley – 2019-04-15T23:38:27.547

1@findusl I don't disagree that the info here is useful, but that doesn't make it an answer. Such content should, at best, be a comment on the question but ideally the answerer can post his own self-answered question e.g. "What is the shortcut in Windows for locking the screen?" (assuming such question doesn't already exist which is unlikely in this case). Answers shouldn't be used to simply post all relevant information - doing so drowns out the real answers (such as the one below which has less votes than this one, despite being an actual answer), which is what this site is for. – Jon Bentley – 2019-04-15T23:41:19.847

@Jon Bentley there is a difference between having to lock your screen by a menu option vs a simple key combination. From work I know that such a key combination can be become muscle memory and then you nearly automatically lock your computer. So I do think it's an XY problem because I think the asker wants his computer to be locked instead of going to sleep when closing the lid. This answer will achieve both. After all the original question is not completely automatic either, because you still need to close the lid. So a human has to be present and then this answer is viable. – findusl – 2019-04-16T05:46:29.517

9

Two steps:

  • Capture the close lid event.
  • Trigger a lock-screen event.

See: Capturing laptop lid closing event in windows?, and Command-line (cmd) command to lock a windows machine.

From those sources, we can use RegisterPowerSettingNotification and GUID_LIDSWITCH_STATE_CHANGE to detect the trigger, and run:

rundll32.exe user32.dll,LockWorkStation 

from the command line to send a lock screen request to the machine.

I don't know what compilers you have available, or what languages you know, but this information should help you set up a program to do it for you.

I don't use Windows myself, so I can't build or test it for you.

mazunki

Posted 2019-04-12T16:57:48.997

Reputation: 235