I want to make my system auto lock whenever I disconnect the Ethernet cable or my LAN signals drops. I'm using Windows 7 and Windows 10.

  • Welcome to Super User! Please note we are not a code-writing service, and questions seeking product recommendations are off-topic. Instead, post specific issues you are having with a script (for example), and folks may be able to help with that. Cheers! – bertieb Dec 1 '18 at 13:44
  • 1
    Also, just supposing hypothetically it happened to be in a corporate environment you wanted to enforce something like that, you may be better off pursuing non-technical avenues of approach. – bertieb Dec 1 '18 at 13:49

According to this answer: http://asianhospital.com/?id=a/225251/950764 an event will be created when your connections drops. The ID will be 27 and the source depends on your network card. (the answer mentions "e1yexpress" but for me it is "e1dexpress")

This allows you to create and event in Task Scheduler that will execute when your connections drops.

  1. Open Event Viewer and filter for Events with the ID 27 and level "Warning" under Windows Logs -> System.
  2. Now you should see events mentioning your network cards name and the text "Network link is disconnected" (assuming this has been the case till now). Most importantly you will now know the events source, which you need to use for the scheduled task.
  3. Open Task Scheduler and create a new task.
  4. In the properties window that opens give the task an name.
  5. In the Trigger tab create a new trigger and select "On a new event". Set Log to "System", source to the name you got from Event Viewer and Event ID to 27. Press OK.
  6. Now go to the Actions tab a and create a new action. In the windows that opens select "Start a program" and enter rundll32.exe as program path and user32.dll,LockWorkStation as arguments .
  7. You may want to customize the task a bit further like disabling the fact that the task will only run if the power is plugged in under the Conditions tab (mostly relevant for laptops)

    After doing this I recommend disconnecting your network cable to check if everything works as expected.
  • I will try it. Thanks for very informative/applicable answer. – CYREX Dec 1 '18 at 14:18
  • It worked at my home computer. I want to implement it at my office. I m using windows server 2008 as a server and i want to deploy this task to all my domain users. As every system has its own network card and source will be different for each computer. Is there anyway i can put universal source name for network disconnection or i have to go to each computer to create that task? – CYREX Dec 1 '18 at 14:58
  • In that case you could switch the trigger from Basic to Custom. If you press new Event Filter and switch to "By source" you can select multiple sources. If you only have very few computer models you could check there event logs and see how the source is called and add them all. – User025 Dec 1 '18 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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