Put Desktop to sleep from Laptop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PAB
Posts: 146
Joined: 12 Aug 2019 13:57

Put Desktop to sleep from Laptop

#1 Post by PAB » 24 Feb 2025 06:58

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.


PAB
Posts: 146
Joined: 12 Aug 2019 13:57

Re: Put Desktop to sleep from Laptop

#3 Post by PAB » 24 Feb 2025 13:46

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.

miskox
Posts: 648
Joined: 28 Jun 2010 03:46

Re: Put Desktop to sleep from Laptop

#4 Post by miskox » 24 Feb 2025 23:53

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

jeb
Expert
Posts: 1058
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Put Desktop to sleep from Laptop

#5 Post by jeb » 24 Feb 2025 23:53

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


Post Reply