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 :
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:
val String results1 = executeCommandLine("C:\\Users\\fals3illusion\\Desktop\\ComputerShutdown.bat", 5000)
and i get
[WARN ] [clipse.smarthome.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: 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)
First of all you should check if your shutdown.exe command is running, by doing the following steps manually.
Type on JUSTIN-COMPUTERregedit (in “Search” or “Run”) and press Enter.
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.
Right-click System folder.
Select “New -> DWORD (32-bit) Value.”
Enter the label: LocalAccountTokenFilterPolicy
Double-click the value, and change it to “1.”
Close and exit the registry.
Reboot to confirm changes. (You can now shut down or restart your PC remotely.)
After restart --> Next, click Search and type Command Prompt.
At the Command Prompt type: net use \\JUSTIN-COMPUTER /User:JUSTIN-COMPUTER\fals3illusion your-password and press Enter.
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.
Last step:
your rule:
val String results1 = executeCommandLine("C:\\Openhab-folder\\conf\\scripts\\shut-down.bat", 5000)
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)
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 ] [clipse.smarthome.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: 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 ] [clipse.smarthome.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: 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)
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 ] [clipse.smarthome.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: 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)
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.