Page 1 of 1

Commands to be carried out by the Pi 3b+

Posted: Wednesday 16 May 2018 3:27
by Pieter
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)

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

Posted: Wednesday 16 May 2018 5:33
by ben53252642
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

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

Posted: Wednesday 16 May 2018 6:17
by Egregius
This should do it: https://sourceforge.net/projects/winexe/
I hope it’s not judt for windows - L?

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

Posted: Wednesday 16 May 2018 6:55
by Pieter
Good morning ben53252642,

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

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

Posted: Wednesday 16 May 2018 6:59
by ben53252642
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?).

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

Posted: Wednesday 16 May 2018 7:13
by Pieter
Hell yes! The screens all went out. And now in linux, can you help me a little bit?

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

Posted: Wednesday 16 May 2018 7:29
by ben53252642
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"

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

Posted: Wednesday 16 May 2018 16:31
by Pieter
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?

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

Posted: Wednesday 16 May 2018 16:38
by Pieter
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