C++: Remotely hibernate a PC

799 Views Asked by At

How can I hibernate a Windows machine that runs Windows 7 or 8 over my LAN from another PC?
Is there a WinAPI function for that? Or do I have to send special magic packets or something like this?
All I know is that PsShutdown.exe is able to do it (allegedly. I haven't tried it).

I don't want to use third party libraries and I also don't want to run a service on the computer that is supposed to get hibernated. I want to use the existing mechanism.

I'd also like to know if I need to change specific settings on the target computer. I'm not sure if that's important, but shutdown /s /m \\ComputerName did not work on my target PC.

2

There are 2 best solutions below

0
On

To the best of my knowledge, the only way to remotely hibernate a machine is to use the same method that psshutdown does: copy an executable to the remote machine and install it as a system service.

The OpenSCManager API allows you to specify a target computer, and you can use the handle it returns to call CreateService and then StartService. The service can delete itself once it has done its work.

5
On

The TechNet document Restart or Shut Down a Remote Computer and Document the Reason describes the requirements to use the shutdown.exe command against a remote computer.

  1. In order to use this feature, the Remote Registry service must be enabled on the remote computer.

  2. Access to the Remote Registry or membership in the Administrators group on the remote computer is the minimum required to complete this procedure