Method to shutdown computer

Great application! so much can be done with it.
I would like to have a button to shutdown the computer in the Win10 app. I tried using the windows shutdown command using the method action openURI, but could not get it to work. Tried “C:\windows\system32\shutdown.exe /s /hybrid /t 3”. Even created a .bat file with the command, referencing it with the same method. No luck.
Any suggestions?
Thanks

I don’t think you will be able to call a file like that. This is a UWP app so Microsoft has extra isolation & security built-in for these apps. I really don’t think you’ll be able to access anything from the file system.

You need to find an actual URI or add a service that listens to a URI. URI’s typically start with a scheme name then a colon. Much like a web URL with “http:” They don’t all have to start with HTTP. For example, the Spotify Windows app has a few registered URIs. If I type “spotify:” in Microsoft Edge it will attempt to launch the Spotify app. Home Remote actually has a few URIs of its own too.

Look into MCE controller.

Yes, that was my first plan and had started going that route with MCE controller. However, for some reason I couldn’t get the Homeremote windows app to connect to the MCEC server on the same computer. Worked under the designer. Performed a lot of tracing and it seems like it has to do with deep firewall filtering that cant be turned off, unless you disable the actual firewall service which is probably not a good idea.
Kinda stuck now- I would also like to spawn other external programs. Setting up something that will respond to a URI is a bit beyond me right now.
Thanks for the suggestions though.

I am using my Vera hub to send the MCE shutdown command and I just trigger the scene through Home Remote. Never had any firewall issues.

Thanks, I was wondering if there might be Vera functionality to do this. I’ll look in to it.

@bill, is there any reason the Home Remote app for Windows wouldn’t be able to connect to the MCE Controller running on the same machine? I believe @mkmass’s question really stems from that issue, which he had initially asked about here. It seems to be some kind of permissions/firewall-related issue. It is really strange because as I understood it, the designer/simulator is able to connect to it fine, it’s only the HR windows app that has a problem.

Here is the MCE controller lua to use with Vera. Just change to your IP.

–[[Turn computer off–]]
local socket = require(“socket”)
tcp = assert(socket.connect(“192.168.1.1”, 5150))
tcp:send(“shutdown” … “\r\n”)
luup.sleep(1050)
tcp:close()

I can’t think of any reason why that wouldn’t work.

Puzzles me too.
Anyone out there actually have this working?
Appreciate all the support from this great community!

How many different network adapters do you have enabled on this machine? Do you have any VPN or virtual machines running? My 1st guess would be that it’s a networking issue & not firewall.

And maybe instead of using an IP address, try “localhost”.

I do have a Fortigate VPN installed for work. However, I also tried on another computer without a VPN adapter. I have tried localhost, 127.0.0.1, same. When I set the firewall to collect a log, it seemed to indicate dropped packets. Also tried a separate simple project just set up to test the communication with same results. Disabled the firewall service, worked.

If disabling the firewall fixed it then I guess it is firewall related. Couldn’t you add a rule to allow this?

Is Home Remote given access in the “Allowed Apps”?

Control Panel\All Control Panel Items\Windows Defender Firewall\Allowed apps

Yes, home remote was already registered in the allowed apps configuration of the firewall. I also tried adding a firewall rule for port 5150. Tried turning off the firewall for the private network connection(which is the one I am connected to)- no dice

John, tried your lua code on my vera in a scene, getting error “Error in lua for scenes and events” tried it in develop apps under test luup code and get error failed to test code please try again

Sometimes copying and pasting into these forums messes up the format. Try copying from the attached text file Open in notepad or notepad ++. Remember to set the IP.

Shutdown_Lua.txt (177 Bytes)

Thanks John. I was able to get it working by typing it in manually, so you are right, must have been something in the cut and paste.

Great, I am sure the txt file will work in case someone else needs it… I uploaded one Friday night and discovered after that one failed the lua test as well. I think it is an issue with copying from the Chrome browser. I tried it again with the MS edge browser and that one worked so I overwrote the original txt file with the new one that works with a copy out of notepad.