Page 1 of 3

Shutdown Remote Windows PC

Posted: Monday 18 November 2013 1:47
by simon_rb
Hi,

Just wondered if anyone out there is doing this? I assume the best way would be some sort of script. I have done a bit of googling.. Found this:-

net rpc shutdown -I IPADDRESS -U USERNAME%PASSWORDP

Not tried it yet, any other ways? Example scripts?

Cheers
Simon

Re: Shutdown Remote Windows PC

Posted: Wednesday 20 November 2013 8:24
by elythomaslumber
Hi Simon,

can't deliver a final solution but since some days I'm working on something similar.
I've a Synology NAS and would like to initiate a "poweroff" command after my Domoticz Raspy has done an automatic backup on the NAS.

Therefore I'm experimenting with this in a batch script on the Raspy:

Code: Select all

#!/bin/sh
get_poweroff_commands | telnet NAS-IP-Adress
or

Code: Select all

#!/bin/sh
get_poweroff_commands | ssh -t -t NAS-IP-Adress
This means I would like to open a SSH or Telnet session on the NAS remotly and then starting a command file stored on the NAS like:

Code: Select all

passwd="xxxxx"
echo ${passwd}
sleep 2
echo ${poweroff}
sleep 1
echo exit
With SSH it's hard since you've to handle certificates and I'm a noob on NAS and Linux. Maybe it's easier to use telnet but anyway it's hard for me to get it running. But maybe this gives you a starting point for your own experiments :lol:

Regards

Hardy

Re: Shutdown Remote Windows PC

Posted: Wednesday 20 November 2013 9:46
by simon_rb
Hey,

Thanks for the info. Will look into it. Unfortunately my Raspberry has corrupted my SD card and looks like I have lost everything!!!

I'm hoping to access the data on the card. Just trying to find out what Domoticz files I need to save my beloved project! I have over 70 switches and 2 dozen scripts. Damn Linux! Lol

Cheers bud.

Re: Shutdown Remote Windows PC

Posted: Saturday 23 November 2013 17:47
by mbliek
I don't know about windows, but with my Mac I needed to add the rsa fingerprint from my raspberry root to my Mac.

Now I can shutdown my Mac using a dummy switch in domoticz.

When I'm back home, I will post my script for you.

Re: Shutdown Remote Windows PC

Posted: Sunday 24 November 2013 12:44
by simon_rb
Ah, that would be great.. Hope I can get it to work with a windows pc. I have managed to recover my data and am back up and running :-)

Re: Shutdown Remote Windows PC

Posted: Monday 25 November 2013 16:51
by mbliek
I don't think you can use this script for windows.
But here is my script anyway.

shutdown.sh

Code: Select all

#!/bin/bash

# connect too iMac
ssh -t -t [email protected] sudo shutdown -h now <<\EOF
PASSWORD
exit
EOF
I think you need too look at something like this:

Got this from stackoverflow:
Command to shutdown windows system from linux -:

$ net rpc -S <ip address> -U <username>%<password> shutdown -t 1 -f

This command can be issued from bash or even set in cron job to shutdown the computer at a specific time and this command is shipped with many distros by default.

Re: Shutdown Remote Windows PC

Posted: Monday 25 November 2013 17:08
by Keptenkurk
At work we use PsTools, a commandline tool, to do all kinds of fancy things on a 1000 remote windows clients.
Shutting down is one of the options but there is much more like killing and starting processes etc.
/paul

Re: Shutdown Remote Windows PC

Posted: Tuesday 26 November 2013 19:35
by simon_rb
Hi,

Thanks everyone for your ideas and suggestions. I think I have PStools on my windows PC, I use squeezeboxes at home and an addon I have installed required me to install it. Do you know how to trigger force shutdown via PStools in a script from linux?

I'll try the one above later, thanks for that! :)

Re: Shutdown Remote Windows PC

Posted: Tuesday 26 November 2013 19:46
by simon_rb
Couldn't get the above script to work... hmmmmm

Re: Shutdown Remote Windows PC

Posted: Tuesday 26 November 2013 19:48
by mbliek
Sorry. Can't help you to test it. Don't own a windows PC.

Re: Shutdown Remote Windows PC

Posted: Tuesday 26 November 2013 20:55
by Keptenkurk
Sorry Simon, the PSTools is a windows <--> windows thing, didn't read your post carefully enough :oops:
To use mbliek's proposed "net rpc" you will need to have samba installed first.

pi@raspberrypi~$ sudo apt-get install samba
pi@raspberrypi~$ sudo apt-get install samba-common-bin
pi@raspberrypi~$ sudo apt-get install smbclient

after which you shoul be able to:
net rpc shutdown -I server_ip -U username
(from: http://www.raspberrypi.org/phpBB3/viewt ... 37&t=56192)

ow .. and i might add this disclaimer: I've never done this either - just reading the same stuff as you...

Shutdown Remote Windows PC

Posted: Wednesday 27 November 2013 0:23
by simon_rb
Cheers Keptenkurk! Will try it out tomorrow :-)

Shutdown Remote Windows PC

Posted: Wednesday 27 November 2013 12:57
by simon_rb
I installed samba and I get the same error which is line 3: $: command not found. Hmmm

Edit:- I have edited my bash script to:-

net rpc shutdown -I server_ip -U username (with my details)

Edit 2:- When running from root I get this

root@raspberrypi:~# net rpc shutdown -I 192.168.1.27 -U [email protected]
Enter [email protected]'s password:
Could not connect to server 192.168.1.27
Connection failed: NT_STATUS_BAD_NETWORK_NAME
Could not initialise pipe \winreg. Error was NT_STATUS_OBJECT_NAME_NOT_FOUND

Re: Shutdown Remote Windows PC

Posted: Wednesday 27 November 2013 13:29
by simon_rb
The problem appears to be my Windows PC itself, command looks good. I'll let you know if I get it to work..

Re: Shutdown Remote Windows PC

Posted: Wednesday 27 November 2013 14:56
by simon_rb
Sorted.

Appears to be working at the mo, next thing to do is to ping the computers to see if they are on..

Thanks everyone.

If anybody wants to use this and is struggling to get it to work, post here and I'll make a quick tut.

Cheers

Re: Shutdown Remote Windows PC

Posted: Thursday 12 March 2015 22:28
by Pablo
Hello,

I'm able to shut down my windows computer from command line by typing net rpc -S 192.168.0.14 -U Admin%password shutdown -t 1 -f

I've made a script using nano, it looks like this:

Code: Select all

#!/bin/bash
#Shutdown Computer
net rpc -S 192.168.0.14 -U Admin%password shutdown -t 1 -f
I've chmod 775 the file
I've named the script Shutdown_PC
In domoticz i've made a virtual button with in the off action field => script://Shutdown_PC
When i push the button nothing happens.

What i'm I doing wrong?

Re: Shutdown Remote Windows PC

Posted: Friday 13 March 2015 5:19
by mbliek
You need to use the full path

script:///home/pi/domoticz/scripts/Shutdown_PC.sh

Note the 3 time /

Re: Shutdown Remote Windows PC

Posted: Friday 13 March 2015 10:58
by Varazir
mbliek wrote:You need to use the full path

script:///home/pi/domoticz/scripts/Shutdown_PC.sh

Note the 3 time /
is the third / needed ?
I got it to work with just two.

//Daniel

Re: Shutdown Remote Windows PC

Posted: Friday 13 March 2015 12:03
by mbliek
It was needed before. Maybe it changed...

Re: Shutdown Remote Windows PC

Posted: Sunday 15 March 2015 11:10
by PeterFleur
I have the same problem with the script. But in the Log of Domoticz i see:
Error: Error executing script command (/volume1/@appstore/domoticz/scripts/lua/shutdown_pc.lua). returned: 32512
When i run the script with a normal ssh connection to my Synology it works fine. Script is chmod 775.

What does error 32512 mean?

Peter