Windows PC remote control (Shutdown, ...)

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:

Thom,

i would like to get this running on my HTPC do you have any tutorial info on the process to get the Java files to run on windows? I have my MQTT broker set up on a PI3 running openhab but I am confused as to setting up the winthing files on my HTPC. There is very little information about the actual install on the Github page. Let me know if you could help with the necessary command lines. Thanks

Create a bat file, then link it in the Autostart start menu subfolder. The bat contains something similar to:

start javaw -jar -Dwinthing.brokerUrl=tcp://openHABianPi:1883 -Dwinthing.brokerUsername=openhab -Dwinthing.brokerPassword=abcdef -Dwinthing.topicPrefix=winthing-pc winthing-1.1.0.jar

I wanted to write a tutorial on the complete topic of interacting with a windows PC. I did not do that yet :sweat:

You need to “escape” the percent sign by putting another percent sign in front of it. I know it sounds weird but it’s a programming thing with special charters.

So it would be command=“net rpc shutdown -I 192.x.x.x. -U MyUser%%SuperSecret”

You can look at the conversation on Stackoverflow for more info.

Good Luck,
Beetle

Ps. This might be what your looking for.

Sorry to ask but where do i get this .jar files ??

'cause when i go to the url link to Github all files I get there now i get in a .zip file and theres a lot of files in that .zip file but no winthing.jar files…Im confused and new to this but I really love openhab2 and got a lot of sonoff stuff working with my setup today and a mqtt server on raspberry pi 3 and feel that the next step now I want to control some software on my windows 10 machine.

/Marcus

2 Likes