Shutdown Remote Windows PC

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Shutdown Remote Windows PC

Post 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
User avatar
elythomaslumber
Posts: 56
Joined: Friday 12 July 2013 13:29
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Solingen; Germany
Contact:

Re: Shutdown Remote Windows PC

Post 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
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Shutdown Remote Windows PC

Post 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.
User avatar
mbliek
Posts: 194
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Shutdown Remote Windows PC

Post 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.
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Shutdown Remote Windows PC

Post 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 :-)
User avatar
mbliek
Posts: 194
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Shutdown Remote Windows PC

Post 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.
User avatar
Keptenkurk
Posts: 103
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: Shutdown Remote Windows PC

Post 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
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Shutdown Remote Windows PC

Post 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! :)
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Shutdown Remote Windows PC

Post by simon_rb »

Couldn't get the above script to work... hmmmmm
User avatar
mbliek
Posts: 194
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Shutdown Remote Windows PC

Post by mbliek »

Sorry. Can't help you to test it. Don't own a windows PC.
User avatar
Keptenkurk
Posts: 103
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: Shutdown Remote Windows PC

Post 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...
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Shutdown Remote Windows PC

Post by simon_rb »

Cheers Keptenkurk! Will try it out tomorrow :-)
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Shutdown Remote Windows PC

Post 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
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Shutdown Remote Windows PC

Post 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..
simon_rb
Posts: 612
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Shutdown Remote Windows PC

Post 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
Pablo
Posts: 1
Joined: Sunday 08 March 2015 12:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Shutdown Remote Windows PC

Post 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?
User avatar
mbliek
Posts: 194
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Shutdown Remote Windows PC

Post by mbliek »

You need to use the full path

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

Note the 3 time /
User avatar
Varazir
Posts: 360
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Shutdown Remote Windows PC

Post 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
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
mbliek
Posts: 194
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Shutdown Remote Windows PC

Post by mbliek »

It was needed before. Maybe it changed...
PeterFleur
Posts: 32
Joined: Sunday 08 March 2015 13:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.4739
Contact:

Re: Shutdown Remote Windows PC

Post 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
RaspberryPI
ZWave
RFXtrx433E
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest