Put a Windows 10 pc remotely to hibernate from a raspberrypi - windows

I'm running homeassistant on a RaspberryPi3 in my local network and what I want to achieve is a switch inside homeassistant to switch on and off my computer (Win10)
Apparently my Desktop PC does not support Wake on LAN from a real "shutdown" to S5, so I'm looking for a solution to remotely hibernate it
What I've done/achieved so far:
- Wake on LAN is working when I manually shutdown with shutdown /h
- remote shutdown is working with net rpc shutdown -I IPADDRESS -U USERNAME%PASSWORD
What I've also tried, but failed:
- running a sshd on Windows (tried with cygwin and openssh port) but failed to start
So the core questions would be either
- If I can manage to put the Windows machine to hibernate instead of shutdown from remote
or
- manage to get WOL working with a completely shutdown machine
Though, Solution 1 would be more convenient to me
Thanks in Advance for any help/hints

I am in the same boat (Home Assistant on a Pi, need to hibernate a Windows computer). I installed this tool from Github on the Windows PC. It's a program that listens for GET requests on a specified port, and will Shutdown, Restart, and Hibernate the host Windows computer.
Now, whenever I send a GET to http://windows.computer.IP.address:PORT/SECRET/ the computer hibernates.

Related

create react app On Your Network with WSL2 not working

I am trying to use a mobile device to view the app served by create react app. When I open the IP:PORT recommended by CRA's "On Your Network", the page never loads on my mobile device.
I am working on Windows 10 laptop, using WSL2 with Ubuntu. My network is all wifi, no ethernet cables. My code is on the Ubuntu file system and I run npm start from the same location in a WSL terminal from VS Code with the WSL extension.
I am able to see the app using http://localhost:3000 with browsers on my Windows machine (Chrome, Edge).
I noticed cmd.exe ipconfig lists the IP address that corresponds to "On Your Network" as "Ethernet adapter vEthernet (WSL)". This IP address (172.17.144.244) is different than what ipconfig shows as "Wireless LAN adapter Wi-Fi" (192.168.1.23). I also tried 192.168.1.23:3000 on my mobile device, but it didn't work either.
Some other posts on SO recommend removing a firewall setting that blocks NodeJS applications. I scrolled through the many applications listed in the firewall settings and found nothing for NodeJS apps.
Since WSL2 uses a virtual NIC what you need is enable port forwarding in the Firewall otherwise your server in WSL2 won't be seen by external PCs in your network.
I recommend reading the entire thread but in resume you can start using this script:
https://github.com/microsoft/WSL/issues/4150#issuecomment-504209723
I had the same issue. So instead of trying to restart the Windows, try to open the Powershell terminal, shut down the WSL, and then start it again. it solves to me.
Command to shut down: wsl --shutdown
Command to start: to start: wsl
Source: https://github.com/microsoft/WSL/issues/4885#issuecomment-803881561
I found a tool that fixes this problem: https://github.com/icflorescu/expose-wsl
First you need to run the command in the wsl terminal
npx expose-wsl#latest
and it gives you an ip address of your pc 192.168.0.130 for example, with that ip you can access the project from devices on the same network.
When running npm start:
.
.
.
On Your Network: http://172.48.228.88:3000
enter on mobile device:
http://192.168.0.130:3000
and works.
Note: You have to allow the port through the Windows firewall. In my case the firewall should allow access to 'C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.3.0_x64__...\wslhost.exe'
You can run your app in Docker instead and use Docker for Windows, enabled for WSL2. It somehow manages dynamic dynamically forward the ports, without having you to change anything in Windows.
I was also having the problem with hot reloading in WSL2 . I tried almost every solution present on github , stackoverflow and where not , from CHOKIDAR_USEPOLLING=true to setting FAST_REFRESH= false in .env file to changing network setting using netsh.... but none of them worked for me and after 2 days of searching solutions and trying to fix it .. finally reverted to wsl 1.
Just run this command on Powershell for now.
wsl --set-version Ubuntu-20.04 1
Consider Nginx for Windows.
I prefer this solution because I'm more familiar configuring web servers and reverse proxies than Windows networking and Powershell.
After unzipping the distribution, for example at C:\somepath\nginx-1.22.1, I add the following reverse proxy configuration to C:\somepath\nginx-1.22.1\conf\nginx.conf
...
http {
...
server {
listen 11500;
server_name wsl2_server;
charset utf-8;
location / {
proxy_pass http://localhost:11500/;
}
}
...
As you can see, I have a web server running on port 11500 in WSL2. When my mobile device requests "lan_ip_of_laptop:11500/", it then forwards to localhost:11500 and WSL2 server completes the request.

problem with an autorun devserver 17 in windows startup on windows 10

I have a program that builds with Delphi and It uses MySQL for DB in Windows 10. I install Devserver 17 but it can not be run in windows startup. I need to run Devserver before my program. I searched on google and used some tips but my problem still alive. for example I use "shellexecuteEx" for run Devserver (run-devserver.exe) when my program start ( on FormCreat event) but it has a delay that is not good for me and give me a new PROBLEMS!. After running the "run-devserver.exe" with "shellexecuteEx", the Http server and database server aren`t running! if I run them manually everything is ok but I want all of them (Devserver and HTTP server and database server) to start automatically before my program.
I use "shellexecuteEx" to execute "eds-dbserver.exe" too but it not working.
I think to avoid a chain of problems I should solve the first problem that is running Devserver and HTTP Server and Database server in Windows StartUp in Windows 10.
I used some tips that not worked for me (in the below):
-Using "shellexecuteEx",
-Run as Administrator,
-change "eds.ini" file : set "Autostart_httpserver=1" and "Autostart_dbserver=1"
-check the windows and antivirus firewall rules
-Run Programs Automatically Using Windows Task Scheduler
please give me a new way.
I had to uninstall devserver 17 and install it again. I put a shortcut of "run-devserver.exe" in the startup folder in this address: "C:\Users\MyPCName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup". the Devserver started on windows startup but HTTP server and database server didn't start. i put a shortcut of dbserver and httpserver to the startup folder too and everything is ok!
dbserver address : C:\Program Files (x86)\EasyPHP-Devserver-17\eds-binaries\dbserver\mysqlxxxx\bin\eds-dbserver.exe
http server address :
C:\Program Files (x86)\EasyPHP-Devserver-17\eds-binaries\httpserver\apachexxxx\bin\eds-httpserver.exe

Port 8005 is used By Windows 10 System Process

Since today, the port 8005 is used for a Windows System Process. When i try to acces to the url http:localhost:8005 ,i can see a Blank Web Page, with no code and no info from any Web Server (No welcome web page or similar).
With the netstat command i can see that the process that uses this port is System process. Any idea why windows is using suddenly this port?
EDIT: Not duplicate question. I don't have another Tomcat installation, the problem comes from a windows process, not for another tomcat instance.
Check if port 8005 is really in use by Windows :
Install and run Sysinternals TCPView and
Check if the line with "Local Port" 8005 has as "Process" System
Or check the file c:\Windows\CCM\Logs\DeltaDownload.log for port 8005
If the port is in use by system, go to Computer Management and stop the service "SMS Agent Host" or open a command prompt as administrator and type:
sc stop CcmExec
The problems comes from a Windows Service:
https://www.niallbrady.com/2017/02/15/how-can-i-use-express-updates-when-patching-windows-10-with-quality-updates-in-system-center-configuration-manager-current-branch/
Not from another Tomcat instance.
I too was facing the same with windows 10 and ran the command netstat -a -b which showed CmRcService.exe is using the port 8005 on the machine.
The most weird part is sometimes if i hit localhost:8005 in the browser url its asking for username and password to access the page and in the developers tools I cannot see any application name or data whatsoever

Shutdown Windows machine from linux terminal [closed]

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 months ago.
Improve this question
I am running an application on linux machine. By giving the ip address of a windows machine as input, the application must shutdown the windows machine. If the machines run the same OS it is very easy but I'm confused how to do it in cross OS.
There may be more setup to do, especially for Windows Vista, Windows 7 and further windows versions, to allow remote shutdown:
Part A) On the Windows machine:
1) Add a remote shutdown security policy:
run secpol.msc
in the program tree, open Security Settings > Local Policies > User rights Assignment
Find the entry Force shutdown from a remote system
Edit the entry, add the windows user account that will be used for shutdown (ex: nouknouk)
2) Add registry keys to disable UAC remote restrictions:
Run regedit.exe as Administrator
Find HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System
Create a new registry DWORD(32) value named LocalAccountTokenFilterPolicy and then assign it the value 1
3) Start remote registry service:
Open cmd.exeas Administrator
Execute the two following commands:
sc config RemoteRegistry start= auto
sc start RemoteRegistry
Part B) On the Linux machine:
1) install the package samba-common:
It depends on your Linux distribution, but for Debian and derivated (Ubuntu, Linux Mint, ...), the apt-get command can be executed like that:
apt-get install samba-common
2) To actually shutdown your Windows machine from the Linux one, run the following command:
net rpc shutdown -f -t 0 -C 'message' -U userName%password -I xxx.yyy.zzz.ttt
Where:
-f means force shutting down all applications (may be mandatory)
-t 0 is the delay before doing it (0 means 'right now').
-U user%password is the local user and his password on the windows machine (the one that has been allowed to do remote shutdown in part A).
-I is the IP address of the windows machine to shutdown.
Command to shutdown windows system from linux -:
$ net rpc -S <ip address> -U <username>%<password> shutdown -t 1 -f
This command can be issued from bash or even set in cron job to shutdown the computer at a specific time and this command is shipped with many distros by default.
It's important to note that the above solution will not work if the username in question does not have a password set (at least that's how it was in my case).
For windows 10 (and below maybe, did not check) users one must go to the firewall settings and enable "Remote Service Management" for the linux box to be able to connect via rpc.
It depends on your infrastructure -- how you authenticate to the Windows machines, whether you can configure them yourself, etc. If it were me, I'd put Cygwin on the Windows boxes, then ssh to them and run shutdown -h. There are surely other ways to do it, of course.
You need a way to launch a shell on the Windows box so you can run th shutdown command built in to Windows.
You can install Cygwin for this, then install an SSH daemon in Windows. Once that's running, your Linux box can run commands on the Windows box just as if it were another Linux machine.
Here are some instructions for setting up Cygwin's sshd in Windows.
Option 1: Install SSH server on windows. Login to this server from any box and call shutdown command. We use Interix(Microsoft's unix like environment). It comes with a telnet server- allows to invoke windows commands from other machines..
Another option:
If you samba installed on windows it can connect to windows and call windows commands
net rpc SHUTDOWN ...
(from http://www.linuxforums.org/forum/red-hat-fedora-linux/60324-remote-shutdown-windows-linux-box.html#post573872 )
Another option:
try rdesktop to the windows machine with shutdown command ( I use it for running windows batch script which has shutdown in it, not sure if you can directly call shutodwn)
For windows 10, install openssh-server following this.
With permission setting by nouknouk here
It should be work by
ssh username#host 'shutdown /p'
Also don't forget to add an inbound rule for RPC in Windows firewall allowing port 445.
Use telnet command in Linux, make sure telnet is enabled in Windows system

Does anyone here uses Linux host/VMWare/VirtualKD debug environment?

Does anyone had a successful experience with VirtualKD setup on Linux host running VMWare Workstation 8 (with Win7 guests)?
Despite the facts there's a lot of admiring comments about 'speed' and 'other benefits' of that VirtualKD, most of them come from Windows/VirtualBox users, and I really don't want to waste my time on trying to get it working on unsupported configuration.
P.S. Official VirtualKD forum has a similar thread that is still unanswered for two years, so decided to ask for reviews here.
P.P.S. My actual problem is that VMWare's socket-based COM port debugging is very slow.. it takes 10 to 20x more time to copy debug output from debuggee to debugger machine, than it takes to print same output to DbgView.
Does anyone had a successful experience with VirtualKD setup on Linux host running VMWare Workstation 8 (with Win7 guests)?
VirtualKD is a Windows-only application. The poster on the forum has worked around the problem of it being Windows-only by redirecting a Unix socket to TCP, therefore allowing Windows clients to connect over the network.
I've used socat to successfully bridge two VMs using a tcp socket. I created pipes in /tmp and ran socat between them; one VM can then debug the other.
In my case, because I'd configured the debugger to use serial connections I was rate limited by the serial connections. I haven't tried the VirtualKD-style setup; however, my bet is it won't work. From the VirtualKD explanation of its internals on VMWare, the client-side code is basically using hypervisor provided functionality. VirtualBox has to be patched by VirtualKD; I expect this is to provide such functionality to VirtualBox clients.
The bad news is this means, ultimately, that the Linux host hypervisor (VMware/VirtualBox on the host) must know to process that information and pass it out to the appropriate location. By default, it won't know how to do this.
I have a successful experience running it on Windows if anyone is looking for that:
Install VirtualBox 5.x or less and create a virtual machine with a Windows .iso SATA device and set it up
Download VirtualKD-3.0
Open the VM and run vminstall.exe on the guest
On admin cmd on the guest: bcdedit /dbgsettings SERIAL DEBUGPORT:1 BAUDRATE:115200
Shut down VM, close VirtualBox and kill the VBoxSVC.exe process
Run VirtualIntegration.exe. If it crashes open an admin cmd and cd to C:\Program Files\Oracle\VirtualBox and then type vboxmanage setextradata <VMNAME> VBoxInternal/Devices/VirtualKD/0/Config/Path <VirtualKD-3.0 folder> i.e. vboxmanage setextradata Windows7 VBoxInternal/Devices/VirtualKD/0/Config/Path C:\Users\lewis\Downloads\VirtualKD-3.0
Open vmmon64.exe and set the debugger path i.e C:\Program Files\Debugging Tools for Windows (x64)\windbg.exe, and then select WINDBG.EXE and start debugger automatically
Launch VM and highlight the VirtualKD entry and press f8 and disable driver signature enforcement and you will soon break into the debugger at nt!RtlpBreakWithStatusInstruction, which is a debugger symbol for the first address of the DbgBreakPointWithStatus, which is called from InitBootProcessor, which is the breakpoint you'd get from sxe ibp;.reboot. There is an earlier breakpoint of sxe ld:nt
You will need to unpatch the VM in order to be able to boot it without vmmon open. VirtualKD is good for logging with debugging protocol packets and automating windbg connection but you can't boot debug with it. In order for boot debugging to work you will need to create a COM1 serial port on the VM and set it to create a pipe \\.\pipe\pipename. You then need to connect to the pipe via windbg manually. Make sure that you have done bcdedit /bootdebug /on && bcdedit /bootdebug {bootmgr} /on && bcdedit /set {bootmgr} debugtype serial && bcdedit /set {bootmgr} baudrate 115200 && bcdedit /set {bootmgr} debugport 1 on the guest before booting.

Resources