Shutting down Windows from Linux

I had to do some research on how to remotely shut down a Windows computer from a Linux host and decided to share :-)

My test environment:


  • Gentoo linux running on my laptop
  • Windows XP SP3 running in a VirtualBox guest


The command (you need Samba installed on your Linux machine):

net rpc shutdown -t 10 -f -C "Remote shutdown initiated" -I 192.168.56.2 -U Erik

Broken down, that becomes:


  • -t 10 to give users 10 seconds to hit Ctrl-S
  • -f to force applications to quit without asking the user to save (so they can't get in the way of the shutdown)
  • -C "Remote shutdown initiated" is the message that should be displayed to any logged-in users
  • -I 192.168.56.2 the IP address at which the machine to shut down is located. In my case, the host-only network adapter
  • -U Erik is my username on the Windows machine. Works also as \ (don't forget to escape the backslash if your shell requires it!) or as \
  • If you like, you can add -r to reboot the machine instead of shutting it down.


If you don't want to be asked for your password, append it to your username with a % sign, like so: -U %

Of course, with Windows being involved, this doesn't work right out of the box ;-) In my case, after being asked for the password the net rpc command reported "Shutdown of remote machine succeeded". The Windows XP machine didn't shut down. It didn't even show me a message. A little Wireshark magic ended up revealing the error code "WERR_ACCESS_DENIED" being sent across the wire. (note to self: maybe a newer version of samba will actually do something with this error?)

Long story short: the solution is to have file sharing enabled, but to disable simple file sharing. To do so, open Explorer, go to Tools -> Folder options -> View (yes, it's the most logical place to put this ) and uncheck "Use simple file sharing" (all the way at the bottom of the list).
Bash tricks 0 comments
This item is closed, it's not possible to add new comments to it or to vote on it