Commands to be carried out by the Pi 3b+

Post Reply
User avatar
Pieter
Posts: 14
Joined: Wednesday 25 April 2018 23:10
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Almere, Nederland

Commands to be carried out by the Pi 3b+

Post by Pieter » Wednesday 16 May 2018 3:27

Good night Support,

Is there a way to use the Raspberry Pi 3b+, and then execute commands in Windows 10 Pro? Example: If there is no movement for 5 minutes, the monitors must dim. You do this in Windows with: Start+L (Windows-key+L)
Regards,
Pieter

English is not my language.
Forgive me if I make a language mistake

ben53252642
Posts: 534
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Commands to be carried out by the Pi 3b+

Post by ben53252642 » Wednesday 16 May 2018 5:33

One way would be to setup an SSH Server on the Windows host then use something like nircmd with sshpass (apt-get install sshpass) on the Raspberry.

Eg, from the Raspberry (not exact) to execute a command on the Windows PC, it would look something like this:

sshpass -p "PASSWORD" ssh "USERNAME"@"IPOFWINDOWSCOMPUTER" "pathtonircmd.exe nircmandcommand"

https://www.nirsoft.net/utils/nircmd.html

User avatar
Egregius
Posts: 2747
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Commands to be carried out by the Pi 3b+

Post by Egregius » Wednesday 16 May 2018 6:17

This should do it: https://sourceforge.net/projects/winexe/
I hope it’s not judt for windows - L?

User avatar
Pieter
Posts: 14
Joined: Wednesday 25 April 2018 23:10
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Almere, Nederland

Re: Commands to be carried out by the Pi 3b+

Post by Pieter » Wednesday 16 May 2018 6:55

Good morning ben53252642,

No matter what I do, the cursor keeps flashing. But beyond that, nothing happens to the monitor.
Regards,
Pieter

English is not my language.
Forgive me if I make a language mistake

ben53252642
Posts: 534
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Commands to be carried out by the Pi 3b+

Post by ben53252642 » Wednesday 16 May 2018 6:59

Personally I'm using this .bat file to turn the screen off on Windows 10

TurnoffScreen.bat

Code: Select all

powershell -WindowStyle Hidden -NonInteractive (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)
You can test it by pasting that code straight into cmd, be careful not to move the mouse (screens should turn off?).

User avatar
Pieter
Posts: 14
Joined: Wednesday 25 April 2018 23:10
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Almere, Nederland

Re: Commands to be carried out by the Pi 3b+

Post by Pieter » Wednesday 16 May 2018 7:13

Hell yes! The screens all went out. And now in linux, can you help me a little bit?
Regards,
Pieter

English is not my language.
Forgive me if I make a language mistake

ben53252642
Posts: 534
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Commands to be carried out by the Pi 3b+

Post by ben53252642 » Wednesday 16 May 2018 7:29

On Windows:

1) Create folder in C drive called: scripts
2) In notepad paste the contents of this:

Code: Select all

powershell -WindowStyle Hidden -NonInteractive (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)
Save the file in the scripts folder on C drive, be sure the file is named exactly: TurnoffScreen.bat
When you go file save as in notepad, you will see its by default set to save as type "Text Documents", change that to "All Files" before saving.
3) Now you should be able to double click TurnoffScreen.bat in the scripts folder and it should work.
4) You now need to remotely tell Windows to run that file when you want the screens to turn off.
5) Setup OpenSSH server on Windows so we can connect to its command line remotely from the Raspberry, suggest follow this or similar guide:
https://www.bleepingcomputer.com/news/m ... sh-server/
6) Make sure you set a static IP address on the windows PC

On Raspberry:

1) apt-get install sshpass
2) ssh -l username STATICIPADDRESSOFWINDOWSPC
3) Make sure you can login with the above command to the Windows PC.
4) Now all you have to do is tell SSH to execute a command on the host Windows PC and automate the process
Eg:

Code: Select all

sshpass -p "PASSWORD" ssh "USERNAME"@"IPOFWINDOWSCOMPUTER" "c:\scripts\TurnoffScreen.bat"

User avatar
Pieter
Posts: 14
Joined: Wednesday 25 April 2018 23:10
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Almere, Nederland

Re: Commands to be carried out by the Pi 3b+

Post by Pieter » Wednesday 16 May 2018 16:31

Sorry for the delay. But I fell asleep!

> On Raspberry:

> 1) apt-get install sshpass
> 2) ssh -l username STATICIPADDRESSOFWINDOWSPC
I am getting an error here: Permission denied, please try again.

> 3) Make sure you can login with the above command to the Windows PC.
I can not login to my Windows 10 Pro PC, do you have any ideas?
Regards,
Pieter

English is not my language.
Forgive me if I make a language mistake

User avatar
Pieter
Posts: 14
Joined: Wednesday 25 April 2018 23:10
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Almere, Nederland

Re: Commands to be carried out by the Pi 3b+

Post by Pieter » Wednesday 16 May 2018 16:38

Egregius wrote:
Wednesday 16 May 2018 6:17
This should do it: https://sourceforge.net/projects/winexe/
I hope it’s not judt for windows - L?
No, that would be very much a waste of your and my time ;-)
UPdate!!
I get one error message after another and it keeps on going. I do not get it installed. This is absolutely nothing for beginners! And that's why everything has been cleared away. With the following command: sudo rm -rf folderName. Bye bye WinExe.
https://www.raspberrypi.org/forums/view ... p?t=158795
https://www.raspberrypi.org/forums/view ... 36&t=50771
Regards,
Pieter

English is not my language.
Forgive me if I make a language mistake

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest