Execute a .Bat file on a remote Windows

Hello Community!

I’m a brand new user, I discovered the solution 2 days ago. I went throught a lot of videos and tutorials but I still need help to figure it out how to configure HassOS 4.15 0.116.4 in the most efficient way.

For a project, I need to play 2 different music files (they can be triggered independently), mixed them together and stream them over HTTP.
To do that, I’m using 3 different instances of VLC running on a windows machine, 2 for independent playback outputting to a virtual output. Then the virtual output is routed to a virtual input used by the 3rd instance to transcode and stream over HTTP. That part is working like a charm except for the 2 seconds delay to transcode the stream.

So far, I managed to control the 2 different playback instances of VLC remotely under Home Assistant using the vlc_telnet platform.

First thing that I’m trying to do is to be able to launch remotely a batch file, to run the VLC instances, using a switch. I’m struggling to find a proper solution. The documentation nor examples on the Internet are not really user friendly and self-explanatory but if you can give me some clues, I’ll be grateful.
Second thing, less important, would be to go further in the playback management. I would love to manage to lower the volume of the first media file for few seconds while playing the second. I’m looking for the events and scripts but I’m not at this step yet.

Looking for your inputs!


I managed to do the second point with some scripts.

I’m still struggling on the first point.

From what I saw, using ssh connection through command-shell might be the best option.

This should be possible with PsExec from MSs Sysinternal Suite

Thanks Joerg.

I don’t really need that layer to launch a bat file. I can do it directly with commands like this in the configuration.yaml and recalled in a script.

    run_vlc_instances: 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa [email protected] C:\Users\xavie\Desktop\vlc.bat'

but at this step I’m getting the following.

2020-10-25 10:43:54 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa [email protected] C:\Users\xavie\Desktop\vlc.bat`, return code: 255

Looks like to be an authentification issue using the RSA keys

Check if PasswordAuthentication is set to no in sshd_config

Thanks again.

What I did so far is to install FreeSSHd on my Windows machine. Add a user called ‘xav’ with Shell usage, Disable the password authentication and force the public key authentication. I’ve created the private and public keys using PuttyGen. Copied the public key into freesshd’s public folder under the same user name ‘xav’ and place the private key into /config/.ssh/xavPrivateNo.ppk (tried with and without passphrase)
When using the SSH add-on to debug the remote access using the same command I’m still having issues

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -oHostKeyAlgorithms=+ssh-dss -i /config/.ssh/xavPrivateNo.ppk [email protected] C:\Users\xavie\Desktop\vlc.bat

By the way, I had to change permissions by typing: chmod 0600 /config/.ssh/xavPrivateNo.ppk otherwise I got a warning: UNPROTECTED PRIVATE KEY FILE.

Now ssh command result is giving an error that I don’t know how to fix:
load key “/config/.ssh/xavPrivateNo.ppk” invalid format

I’m going to check with keys generated by built-in ssh add-on but if you guys have any idea…


I generated new keys using the command “ssh-keygen -t rsa -N “” -f my.key”
now the command below gives no ‘invalid format’ error anymore and I can connect after restarting the FreeSSHd server

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -oHostKeyAlgorithms=+ssh-dss -i /config/.ssh/my.key [email protected] C:\Users\xavie\Desktop\vlc.bat

So now the SSH command to launch a remote BAT script itself works.

but when using it in the command-shell I’m still having issues

2020-10-25 13:41:21 ERROR (MainThread) [homeassistant.components.shell_command] 
Error running command: `ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -oHostKeyAlgorithms=+ssh-dss -i /config/.ssh/my.key [email protected] C:\Users\xavie\Desktop\vlc.bat`, 
return code: 255
NoneType: None

I finally ended up using a scheduler on the windows machine to launch my .bat file.

For some unknown reasons, launching the bat manually works, lauching the bat from ssh command using the add-on works but using the same command within comand_line switches and shell_command stop in the middle of the .bat. Meaning that some actions are done but not the entire .bat file. I didn’t get it.

Anyway found a workaround using that call

    run_vlc_instances_task: "/usr/bin/ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -oHostKeyAlgorithms=+ssh-dss -i /config/.ssh/my.key [email protected] 'SCHTASKS.EXE /RUN /TN \"InstancesVLC\"'"

Calling a planified task called InstancesVLC on the Windows machine.

This is a huge process, if someone does have another solution I’ll be glad to test :slight_smile:

Guess its much easier to us PsExec :wink:

psexec \\machine_name -u 'user' -p 'password' path\filename.bat

I agree but how do you launch psexec from Hassio running on a raspberry ? :grinning:

Upps. Ok, I don’t know why but all the time I was just thinking about Windows. Sorry.
There are tools like xfreerdp but it might be the same hussle.

No worries. Thanks a lot, just to know that someone is reading and tried to help was motivating.