Remote Shutdown of a Windows Computer from Linux
I was away for a few days with my family visiting relatives, but being self-employed it can be hard to take time off, and wouldn’t you know it I had to spend a little time online checking email, finding passwords for people and occasionally just checking in on things at the house through a remote desktop connection to my Windows computer back at home.
The only problem is that after the first night I was not able to connect to the remote desktop. I knew the machine was there, I could SSH into my Linux server and ping the Windows computer but there was no way it would properly connect a remote desktop connection. I had to reboot the Windows machine to see if I could get it back to normal. Thankfully my Linux server uses Samba as well and with a little searching I soon had my answer: http://www.linuxforums.org/forum/ redhat-fedora-linux-help/60324- remote-shutdown-windows-linux-box.html#post573872 net rpc SHUTDOWN -C “some comment here” -f -I x.x.x.x -U user_name%password
I modified it a little bit and came up with this: net rpc shutdown -r -f -I xxx.xxx.xxx.xxx -U username
I entered my password and a few minutes later guess what I was able to do? I was able to connect to my remote desktop on my Windows machine back at home. Linux saves Windows once again.
Comments
islandcenter
Thank you. This idea is usefull for XEN or virtulization environment.
LGR
You are welcome. Glad it was helpful. Thanks for the link as well. Appreciate it.
A.Faith
it tells me this : ~/ $: net rpc shutdown -r -f -I 192.168.2.103 -U fam-Udrescu Password: [2008/07/01 22:43:56, 0] utils/net_rpc.c:run_rpc_command(160) Could not initialise pipe \winreg. Error was NT_STATUS_OBJECT_NAME_NOT_FOUND ~/ $: any idea why?
LGR
Sorry don't know specifically what might be the problem, but it does look like you are giving two user names. Maybe that has something to do with it.
FR
Great. Also a very good way to safe some power during the night. In combination with wakeonlan in the morning, it will save some kw's per year.
LGR
Excellent idea! Set up a cron job to shutdown and wake the Windows machine when you need it. I will have to try that.
Sasktel, Packing, Moving and Top Ten - LGR Webmaster Blog
[...] Remote Shutdown of a Windows Computer from Linux [...]
chronos
for: A.Faith The problem you have is probably not related to the "net rpc" command, but to windows local security policy configuration. See this post at ubuntu forums for details: http://ubuntuforums.org/showthread.php?p=5592041#post5592041 Regards
Fractalspace
Awesome! Worked like a charm.
Oliver Treend
Unfortunately I get that error, too. I think it might have something to do with the fact I'm using Vista Home Premium. I can't use the DOS shutdown command from my XP command prompt to remotely shut down this Vista PC either. It says access is denied when using the DOS shutdown command. My guess is that Vista Home Premium denies all remote shutdowns.
LGR
Could be. I don't have a copy of Windows Vista running to try it out on.
Oliver Treend
It's alright - I found a fix for it now. Turns out it was just 1 simple registry addition. I'll post the URL where I found the help later - I don't have it to hand at the moment.
Jo
Instead of automatic restart / shutdown XP remotely, is there anyway we ask user input? let's say we ask if user click NO within 5 minutes, the shutdown will be aborted
LGR
Not that I am aware of. A quick check on my machine shows the following options for net rpc <blockquote>Usage: net rpc audit Modify global audit settings net rpc info Show basic info about a domain net rpc join Join a domain net rpc oldjoin Join a domain created in server manager net rpc testjoin Test that a join is valid net rpc user List/modify users net rpc password Change a user password net rpc group List/modify groups net rpc share List/modify shares net rpc file List open files net rpc printer List/modify printers net rpc changetrustpw Change trust account password net rpc trustdom Modify domain trusts net rpc abortshutdown Abort a remote shutdown net rpc shutdown Shutdown a remote server net rpc samdump Dump SAM data of remote NT PDC net rpc vampire Sync a remote NT PDC's data into local passdb net rpc getsid Fetch the domain sid into local secrets.tdb net rpc rights Manage privileges assigned to SID net rpc service Start/stop/query remote services net rpc registry Manage registry hives net rpc shell Open interactive shell on remote server </blockquote> There is the option to abort a shutdown, but nothing to ask for user input.