Page 1 of 1

Put Desktop to sleep from Laptop

Posted: 24 Feb 2025 06:58
by PAB
Put Desktop to sleep from Laptop

Good afternoon,

I have managed to investigate, acquire, and adapt a script to wake-up my Desktop computer from my Laptop computer.

My Desktop computer has a shared internal HDD and a shared USB connected HDD which are both available from my Laptop when I wake-up my Desktop from the script run from my Laptop.

This all works as needed. So far so good.

My question is, how can I put the Desktop computer to sleep from my Laptop.

I have a .bat file on the Desktop computers Desktop with the following code . . .

Code: Select all

@echo off
rundll32.exe powrprof.dll,SetSuspendState 0,1,0
. . . which I tested and works if I double click it on the Desktop computer.

I have investigated and tried MANY MANY MANY code snippets to try and run the .bat file [Desk_Sleep.bat] on the Desktop from my Laptop but unfortunately to no avail.

This was just one I tried which did seem promising . . .

Code: Select all

Function Run-BatchFile
{
     param($computer = "<Computer_Name_Here>")
     $BatFileName = "Desk_Sleep.bat"
     Invoke-Command -ComputerName $computer -ScriptBlock {param($BatFileName) & "cmd.exe /c C:\Users\<User_Name_Here>\Desktop\$BatFileName" } -ArgumentList $BatFileName -AsJob
}

Run-BatchFile

PAUSE
Any help will be greatly appreciated.

Thanks in advance.

Re: Put Desktop to sleep from Laptop

Posted: 24 Feb 2025 13:18
by miskox

Re: Put Desktop to sleep from Laptop

Posted: 24 Feb 2025 13:46
by PAB
Thanks for the reply miskox,

Unfortunately that has nothing to do with my problem.

The Desk_Sleep.bat on the Desktop computers Desktop runs correctly if I run it directly on the Desktop computers Desktop.

What I need is to be able to run [EXECUTE] Desk_Sleep.bat from my Laptop.

Thanks again.

Re: Put Desktop to sleep from Laptop

Posted: 24 Feb 2025 23:53
by miskox
Unfortunately that has nothing to do with my problem.
Info in the link:
Seems for Win11 it is turned off to use SLEEP function due to Modern StandBy S0 mode
and
I went into BIOS and changed the sleep mode to Linux (S3) just to see what happens. Then I was able to put the PC to sleep.
Read entire thread.

Maybe this is the reason for your problems?

Saso

Re: Put Desktop to sleep from Laptop

Posted: 24 Feb 2025 23:53
by jeb
If you are using at least windows 10 you could use ssh.

Code: Select all

Laptop> ssh desktopuser@[DesktopName or DesktopIP] "Desk_Sleep.bat"
But you have to enable the ssh server on the desktop Get started with OpenSSH for Windows.

Then you need to create an ssh keypair on your laptop Generate new ssh keys in Windows 10 / 11

Finally, store the public key on the Desktop Key-based authentication in OpenSSH for Windows

Re: Put Desktop to sleep from Laptop

Posted: 25 Feb 2025 01:57
by miskox