Remote Shutdown PC Using EXEC on Windows PC OpenHAB

@fals3illusion

First of all you should check if your shutdown.exe command is running, by doing the following steps manually.

  1. Type on JUSTIN-COMPUTER regedit (in “Search” or “Run”) and press Enter.

  2. Either go to the following registry key: Computer\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System or copy and paste the registry path to the address bar and press Enter.

  3. Right-click System folder.

  4. Select “New -> DWORD (32-bit) Value.”

  5. Enter the label: LocalAccountTokenFilterPolicy

  6. Double-click the value, and change it to “1.”

  7. Close and exit the registry.

  8. Reboot to confirm changes. (You can now shut down or restart your PC remotely.)

  9. After restart --> Next, click Search and type Command Prompt.

  10. Right-click and select “Run as Administrator.”

  1. At the Command Prompt type: net use \\JUSTIN-COMPUTER /User:JUSTIN-COMPUTER\fals3illusion your-password and press Enter.

  2. Type shutdown /r /m \\JUSTIN-COMPUTER /t 001 and press Enter.

If this then reboots your remote PC, then you can do further steps.

If all steps 1-12 are running manually, you now can create a batch file e.g. shutdown.bat with the following content:

net use \\JUSTIN-COMPUTER /User:JUSTIN-COMPUTER\fals3illusion your-password
c:\windows\system32\shutdown.exe /r /m \\JUSTIN-COMPUTER /t 001

.
place shutdown.bat into the following folder:

   C:\Openhab-Folder\conf\sripts\

To auto-run a batch file as administrator, you need to create a shortcut for it. To create a shortcut, right-click the shutdown.bat, and select “Create shortcut”. This will place the shortcut in the same folder. Rename it to shut-down.bat

Once the shortcut has been created right-click it, select Properties from the context menu. On the Shortcut tab, you will see an Advanced button at the bottom. Click it.

image

Last step:

your rule:

val String results1 = executeCommandLine("C:\\Openhab-folder\\conf\\scripts\\shut-down.bat", 5000)
1 Like