Remote Shutdown PC Using EXEC on Windows PC OpenHAB


I am wondering if anyone has any insight on my problem. I currently am trying to switch my OpenHABian Pi to a Windows 10 Version of OpenHAB. I’m guessing the reason is I have so many items/rules/things running on my Pi my system takes over 30 minutes to load up and deploy vs about 2-3 minutes on my old Computer which is now a Storage/Plex server with Windows 10 16GB RAM 3.4 Ghz i5.

So one of my things i do from remote is WOL and Remote Shutdowns. Whenever i run the following :

val String results1 = executeCommandLine("shutdown.exe /m \\\\ /s /f", 5000)
logInfo("FTV", results1)

I get an results1 of : Access is denied.(5)

both username and passwords on the machine i am trying to shutdown and the machine that is sending the shutdown command are the same.

Does anyone know how to get this to work without receiving an access denied?



Check that the user that is sending the command is added to the Local Security Policies of the target machine

EDIT: Do not add “Everyone” to this policy or you’re asking for all sorts of trouble :smiley:

Already tried that, doesn’t seem to work. Even for testing purposes i tried “Everyone” and still said access denied. (5)


Please read the following articles:


You have to add a registry-key.
You have to use the command “net use” first.
Username of the remote machine is: PC-Name\username or IP-Address\username

But you also first can try to add the user of the PC were you execute the command, in the policy of PC that should be shut down:

User = PC-Name\username or IP-Address\username

ALSO IMPORTANT: shutdown.exe has to be running with Administrator rights. See here:

Btw, this was only running with older Windows Versions: e.g. Win9x, WinXp.

This is on both PC’s running Windows 10 Pro

i have tried this

val String results1 = executeCommandLine("C:\\Users\\fals3illusion\\Desktop\\ComputerShutdown.bat", 5000)

and i get

[WARN ] [] - Execution failed (Exit value: -559038737. Caused by Cannot run program "C:\Users\fals3illusion\Desktop\ComputerShutdown.bat" (in directory "."): CreateProcess error=2, The system cannot find the file specified)

I have tried the actual location of the file and get the same thing too

I have tried this with
Justin-Server\fals3illusion (Computer that sends the shutdown command)
and also Justin-Computer\fals3illusion (Computer that receives the shutdown command)

and i get an error that says


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:


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.


Last step:

your rule:

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

This is the error i am getting now once running the script.

C:\openHAB2\userdata>net use \\JUSTIN-COMPUTER /User:JUSTIN-COMPUTER\fals3illusion mypassword1234

'net' is not recognized as an internal or external command,
operable program or batch file.
C:\openHAB2\userdata>c:\windows\system32\shutdown.exe /r /m \\JUSTIN-COMPUTER /t 001
JUSTIN-COMPUTER: Access is denied.(5)



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

Yes, that did it!
Thank You so much for you help !

1 Like

Hello @Celaeno1, thank you so much for the clear instructions! I am attempting to replicate @fals3illusion’s success in remotely restarting the windows 8 laptop I am running OH on- I was successfully able to follow your instructions to the very last step, the executeCommandLine step, but I seem to be having a couple of problems. First, My OH folder is within the C:\Program Files folder of my computer, and the space appears to be at least part of my problem- I can’t figure out how to represent it correctly to the rule so that it can successfully locate the file shut-down.bat (I get the error ‘Cannot run program “C:\Program”’…‘The system cannot find the file specified’). The second problem is that even after I move shut-down.bat to the C:\ directory and point the rule there, I get the exact same error (‘The system cannot find the file specified’)!. Any idea what I am doing wrong here? Thanks so much in advance!

Here is the rule i’m attempting to implement, just like your example:
val String results1 executeCommandLine("C:\\Program Files\\OpenHAB2\\conf\\scripts\\shut-down.bat

Error when I attempt to use the original OH directory within C:\Program Files…

15:58:39.478 [WARN ] [] - Execution failed (Exit value: -559038737. Caused by Cannot run program “C:\Program” (in directory “.”): CreateProcess error=2, The system cannot find the file specified)

Error when I attempt to use the directory C:…

16:01:27.900 [WARN ] [] - Execution failed (Exit value: -559038737. Caused by Cannot run program “C:\shut-down.bat” (in directory “.”): CreateProcess error=2, The system cannot find the file specified)


You also could use Progra~1 (or Progra~2) instead of "Program Files" in your rule, depending on your Windows version (32-bit or 64-bit):

val String results1 executeCommandLine("C:\\Progra~1\\OpenHAB2\\conf\\scripts\\shut-down.bat", 5000) 

Make sure that shut-down.bat is a shortcut to shutdown.bat.

P.S: If you also have a “Program Files (x86)” folder, then you have a 64-bit Windows version.
You can find out whether it is Progra~1 or Progra~2 by executing the following command: dir /X

19.08.2020  14:44    <DIR>          PROGRA~1     Program Files
21.08.2020  13:56    <DIR>          PROGRA~2     Program Files (x86)
1 Like

Aha! That was definitely part 1 of the problem- thank you. But alas, I still get the (new) error below. Strange, because the .bat file works when I run it from Windows manually…

21:56:37.428 [WARN ] [] - Execution failed (Exit value: -559038737. Caused by Cannot run program "C:\Progra~1\OpenHAB2\conf\scripts\shut-d~1.lnk" (in directory "."): CreateProcess error=193, %1 is not a valid Win32 application)

Hey there,

I wrote a tutorial for this a few months ago:

and it works like a charm :slightly_smiling_face:

1 Like


I tried out myself (on Win10, 64-bit, build: 19041.508 ), but it is not running anymore to “execute” via a shortcut directly !! ??? !!

So please create another batch, called e.g.: execute.bat

Content of execute.bat:


your rule:

val String results1 executeCommandLine("C:\\Progra~1\\OpenHAB2\\conf\\scripts\\execute.bat", 5000) 

I tried myself and it is running!


You are a saint, for trying so hard to help me… but I must have a permissions issue or some other configuration error with the laptop I am using to run OH. I attempted the execute.bat change above and although there is now no error in my OH log when I trigger the rule, it does not successfully restart the target Windows laptop running OH. I think that maybe there must still be an issue with not being able to run the execute.bat file as an administrator, because when I launch it in windows explorer, I get a prompt “do you want to allow the following program to make changes to this computer?” - and if I click yes, it successfully restarts! I am at a loss.


Thank you for the info! I think I did stumble upon your tutorial- I haven’t tried it yet because I have OH running on a Windows laptop, and to be honest I am not sure how to replicate the “sudo” command in Windows. I believe I have come across a few OH forums alleging that there is no Windows equivalent? I see your comment in step #3 stating “When using Windows as a server this commands should only be somewhat different”… but as a shameless self-taught noob I don’t know how to accomplish those changes myself.

1 Like


Please disable UAC.

Controlpanel --> User Accounts --> Change User Account Control Settings


Also make sure that your shortcut still is running as Administrator. See also above.