Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I remotely lock a Windows 7 computer from linux command line?

They are both on the same lan.

It would also be cool to know how to unlock it, but that isn't as important to me as of now.

share|improve this question
up vote 4 down vote accepted

Your solution must necessarily have two parts if you plan to do this over the network (which is the case since you mentioned "LAN"):

  • The part that sits on the Windows 7 computer and "listens" (waits) for a connection to come in from another computer and perform some action
  • The part that sits on the Linux computer and actively goes out to the Windows 7 computer and makes a connection to make some request

You might start with the reasonably secure notion of running a Secure Shell (SSH) server on Windows. See this ServerFault question for details.

Once you have your SSH server of choice configured on Windows, now you need to be able to remotely login to that SSH server using a client on Linux, which happens to be well-supported on Linux using OpenSSH's ssh command. You can even script it so it logs in, does its work, and logs out automatically, and even set it up with a cron job to execute it automatically!

Now, you're in a situation where you have a "remote terminal" to the Windows PC from the Linux box. Your next question is: how do I lock the screen from the command line? You've got the "transport" set up properly; now you just need to issue the command.

Well, SuperUser already has a question about that.

For your info (to help you be more self-sufficient in the future)

Since your question is a "two-part" question, I won't flag this as a duplicate of that question. But really, if you had analyzed your original question and broken it down into two parts like I did, you'd be able to easily google and find the answers to the separate questions and you'd be off to the races. Learn from this for next time: analyze your problem and divide it into digestible, solvable parts, rather than looking at it head-on as a "unit-problem". Every unit-problem is composed of sub-problems that are simpler, more comprehensible, and importantly, much more likely to already have been solved by other people.

share|improve this answer
I like the comment from the linked article - the user that set up the command to be invoked via web page. – Sam Axe Jan 25 '13 at 0:17
freeSSHd was the answer. Thanks for the advice. – DanielTA Jan 25 '13 at 23:08

Download PSExec and try running it from some Linux-to-Windows environment (like Wine):

PSExec \\computer -u <user> -p <pass> rundll32.exe user32.dll, LockWorkStation
share|improve this answer

Depending on your configuration and needs, you may be able to just use rdesktop to connect via Remote Desktop (passing the -u and -p options to specify username and password). Simply connecting (successfully) should cause the local desktop to be locked.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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