Windows PC remote control (Shutdown, ...)

Hey guys,
I left my apartment over the weekend and just now saw that my PC seems to be active (thanks to the network binding). Does anybody know of a good way to remote control a Windows (10) PC?

I would prefer a dedicated solution. A small application to install on a PC which will then provide some kind of REST interface for all kinds of tasks like shutting down or restarting the PC, starting Kodi, etc.

1 Like

Hi,

I just use the exec binding which runs a little script:

net rpc shutdown -f -I 10.x.x.x -U PCXX\Username%password

Obviously, Iā€™ve made it a wrapper and arguments are supplied from the command issued, but this is the important bit. For added HAB-fu, you could also add ICMP ping monitoring and use a Switch item with Wake-on-LAN to turn the computer on and the command above for shutdown. The WoL binding is very easy to implement, and most desktop machines support it.

{wol="10.x.x.0#00:AA:BB:DF:FE:D6", autoupdate="false", exec="<[/bin/sh@@-c@@ping -c 1 10.x.x.x | grep \"packets transmitted\" | sed -e \"s/.*1 received.*/ON/\" -e \"s/.*0 received.*/OFF/\":30000:REGEX((.*))]"}

The above works fine for me.

Cheers,

PelliX

1 Like

net rpc will work if you run OH on Windows. As you run OH on Linux just as I do, how do you do it there?

EDIT: ok, you can install samba, itā€™s said to bring the ā€œnetā€ command, but on my Raspian (Jessie) Pi it didnā€™tā€¦

Thanks for your answers. net rcp is something I already looked into but itā€™s rather limited and functionality is different between Windows versions, a user with password is needed (I think to remember), ā€¦

Anyhow, Iā€™m hoping to find a more modern and straight forward way to control my different systems without the mess of dealing with Windows. A HTTP / REST Interface with configurable options would be amazing. Something has to be available!? Curiously I was not able to find a good solution.

Maybe Iā€™ll have to install an SSH serverā€¦ still not the set-ready-go solution Iā€™m looking for.

This seems to go in the right direction: http://www.den4b.com/products/shutter

How about Unified Remote?
Itā€™s an app for Android that allows you to control various devices (like Windows machine).
You simply install server app on PC and youā€™re ready to go.

AFAIK they have opened their API some time ago.

Maybe itā€™d be a good candidate for a openHAB Binding?

1 Like

Hi,

indeed, I was referring to the setup in which you run OpenHAB on Linux, and ā€˜controlā€™ the shutdown of a Windows computer. Likewise, I use a shell script which sshā€™es into Linux workstations to shut them down.

Thanks for your answers. net rcp is something I already
looked into but itā€™s rather limited and functionality is different
between Windows versions, a user with password is needed (I think to
remember), ā€¦

Actually, itā€™s net rpc, as in Remote Procedure Call. Yes, on Windows this is (as far as I know) since NT always a an authenticated action. I think the reasoning for that design should be pretty clear.

Running an SSH server on Windows is possible, and from there you can hack just about anything together with tools ranging from PowerShell to KiXtart to batch files, etc. Some applications expose their own interface for remote control purposes like Media Player Classic, VLC or some Bittorrent clients. If I am not mistaken, the SSH service will also require an authenticated login, though.

Cheers,

PelliX

Hey,

was just nosing around for something else and stumbled upon this:

http://kodi.wiki/view/web_interface

Iā€™m not a kodi user, I use a heavily modified Freevo system in a custom ā€˜media center systemā€™ that I wrote and built a while back, but if Iā€™m not mistaken you can add just about any command to kodi, and operate kodi via HTTP commands. That should cover everything you need, no?

Cheers,

PelliX

Hello,

iā€™m using Powershell Server on my Windows 10 PC and the EXEC binding. The solution is not perfect, but it works for me.

Here is an example of 4 commands that i send from OH to start/stop Steam or Plex application.

Rules:

rule "HTPC StartSteam"
when
Item HTPC_StartSteam received command
then 
var String response = executeCommandLine("/usr/bin/sshpass -p '' ssh -o StrictHostKeyChecking=no username@pc start-process steam.bat", 2000)
logInfo("HTPC_StartSteam", response)
end

rule "HTPC KillSteam"
when
Item HTPC_KillSteam received command
then 
var String response = executeCommandLine("/usr/bin/sshpass -p '' ssh -o StrictHostKeyChecking=no username@pc kill -processname Steam", 2000)
logInfo("HTPC_KillSteam", response)
end
 
rule "HTPC StartPlex"
when
Item HTPC_StartPlex received command
then 
var String response = executeCommandLine("/usr/bin/sshpass -p '' ssh -o StrictHostKeyChecking=no username@pc start-process plex.bat", 2000)
logInfo("HTPC_StartPlex", response)
end

rule "HTPC KillPlex"
when
Item HTPC_KillPlex received command
then 
var String response = executeCommandLine("/usr/bin/sshpass -p '' ssh -o StrictHostKeyChecking=no username@pc kill -processname 'Plex Home Theater'", 2000)
logInfo("HTPC_KillPlex", response)
end

the start processes are handled by a batch file and PSEXEC (i put both in the user documents folder at the WIN 10 machine)

Content of plex.bat

psexec -i "c:\program files (x86)\plex home theater\plex home theater.exe"

When I start processes directly throw the executeCommandLine, the processes are starting invisble in the background and not under the logged in user.

My WIN PC has no password and the PowershellServer runs not as service.

Hope this helps.

1 Like

Guys, Iā€™ve found a satisfying solution to my initial question:

Iā€™m utilizing MQTT (which is quite nice as a protocol already widely used in the home automation area). ā€œWinThingā€ is an MQTT client developed in Java to receive all kinds of Windows system commands, including executing a command, opening a URL or shutting down the system. Have a look:

4 Likes

To make this thread complete, hereā€™s a short example, only checking the online state and sending two commands. Itā€™s easily extended.

pc.items:

Switch WZ_PC_Online "PC WinThing Online" { mqtt="<[broker:winthing/system/system/online:state:MAP(truefalse.map)]" }
String WZ_PC_Command "PC Command"

sitemap:

Switch item=WZ_PC_Online
Switch item=WZ_PC_Command mappings=[shutdown="Shutdown", kodi="Start Kodi"]

pc.rules:

rule "PC Command"
when
	Item WZ_PC_Command received command
then 
	switch (receivedCommand) {
		case "shutdown" : {
			publish("broker", "winthing/system/commands/shutdown", "now") 
  		}
		case "kodi" : {
			publish("broker", "winthing/system/commands/run", '["C:/Program Files (x86)/Kodi/Kodi.exe"]')
		}
	}
	WZ_PC_Command.postUpdate(NULL)
end
4 Likes

Hello out there, i am a new beginner to openHAb project.

IĀ“m happy that now my shutter and light configuration is working but now i have a problem with mqqt and win thing.

My goal is to remote shutdown and start 2 Windows 10 PCĀ“s (start maybe with windows login if possible would be great) from openhab
Openhab is running on Synology NAS

Here are the steps iĀ“ve already done. only to be sure thats the right way.
I have installed mosquitto-1.4.11-install-win32 on one of the Windows 10 PcĀ“s only one first to test (i found a guide i copied the dlls and everything seems to be running fine. It also starts as a Service should work perfect.

Then i start the Winthing.jar manually through windows cmd console (first afterwars it will work automatically)

java -jar -Dwinthing.brokerUrl=tcp://localhost:1883 -Dwinthing.brokerUsername=bob -Dwinthing.brokerPassword=supersecret11 -Dwinthing.clientId=WinThing -Dwinthing.topicPrefix=winthing -Dwinthing.reconnectInterval=5 C:/winthing.jar

then i see in CMD that it seems to be running:

i got status messages from engine: like winthing/system/commands/open and alle the others
and at least: Subscribed, Sending initial Message, Engine Started

So hopefully it looks like its running

I have copied exactly the items the rule and to test also the sitemap from above to the conf folder openhab.

But now its not working.

in events.log i see:

WZ_PC_Commandā€™ received command shutdown
2017-05-20 08:47:00.620 [ItemStateChangedEvent ] - WZ_PC_Command changed from NULL to shutdown
2017-05-20 08:47:00.732 [ItemStateChangedEvent ] - WZ_PC_Command changed from shutdown to NULL

and on openhab.log:

i have nothing

informations: installed openhab 2.1 snapshot and mqqt binding and also action but still not working

maybe you have an answer for me to get this fixed. or other solution for remote pc start/shutdown start progamm etc ā€¦

thanks in advance for helping

I

Hey! As always when dealing with MQTT you should use an mqtt client on another device to debug the communication betwen your devices. For PC i can recommend mqtt-spy, for android or iOS youā€™ll also find apps. Use one of these to troubleshoot the communication.

Yeah, following on from this, I use MQTTBox on Win10 from the Windows Store, and MQTT Dash on Android.

Are you using the 2.0 Exec?

net rpc shutdown works fine if use it from the Terminal, but if I put it in a thing with the exec binding
http://docs.openhab.org/addons/bindings/exec/readme.html#binding-configuration

I get an Error because of the % in -U user%pass

and is there maybe a way where donā€™t need to put my password in the things file?

Anyway, Iā€™m using openHAB since yesterday on a Raspberry and I love it =D

Cheers,
Mourkain

Hi everybody!

First thanks for the given solution!
I think i done every step like you guys but it seems that i got an problem with the rules above.

Here are the steps iĀ“ve done. Installed and configured mosquitto as broker on my raspberry. As client i tried to use my Windows10 PC, with winthing service. Inside openhab iĀ“ve configured items, sitemap and rules like @ThomDietrich. So far so good.

The connection between mosquitto and my winthing clients works fine! IĀ“ve tested the connection with MQTTlens application from chrome and was so able to send and execute commands on my Windows10 Client. Perfect!

The only thing that doesnt work is the execution from openhab. My log for the rule:

2017-07-06 10:20:31.886 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'PC Command': An error occured during the script execution: The name 'publish(<XStringLiteralImpl>,<XStringLiteralImpl>,<XStringLiteralImpl>)' cannot be resolved to an item or type.

I also tried to create an item like:

 Switch WZ_Test "PC WinThing test" { mqtt=">[mosquitto:winthing/desktop/commands/close_active_window:command:close_active_window:1]"}

but also no success. Perhaps someone can help me with the mqtt commands in openhab.

thanks in advance for helping

Have you installed publish action?
http://docs.openhab.org/addons/actions/mqtt/readme.html

2 Likes

thanks! Finally it works :slight_smile:

@ThomDietrich can you share how you integrated this into Habpanel? Thanks

I did not. :smile: