Solved Batch file to put computer to sleep


glasskuter

Well-known member
Pro User
VIP
Local time
2:31 AM
Posts
2,900
Location
Paris in the Lone Star State of Texas
OS
Windows 11 Pro 22H2 22621.819
Calling on all you cmd line gurus out there...I'm not too sharp using the cmd window. I have tried various methods to make a shortcut to sleep my PC. I finally got it to work by making a batch file and then making a shortcut to the batch file that I pinned to the taskbar. My problem is, the cmd window is left open after the cmd runs. Not too big of a deal but it irks me. What do I need to add at the end to make cmd automatically close after it runs. Here's the batch file.

powercfg -h off
rundll32.exe powrprof.dll,SetSuspendState 0,1,0
powercfg -h on
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 22H2 22621.819
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 7080
    CPU
    i9-10900 10 core 20 threads
    Motherboard
    DELL 0J37VM
    Memory
    32 gb
    Graphics Card(s)
    none-Intel UHD Graphics 630
    Sound Card
    Integrated Realtek
    Monitor(s) Displays
    Benq 27
    Screen Resolution
    2560x1440
    Hard Drives
    256 m.2 2230-256+1 tb hdd
    PSU
    500w
    Case
    MT
    Cooling
    Dell Premium
    Keyboard
    Logitech wired
    Mouse
    Logitech wireless
    Internet Speed
    so slow I'm too embarrassed to tell
    Browser
    Firefox
    Antivirus
    Defender+MWB Premium
  • Operating System
    Windows 10 Pro 21H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 9020
    CPU
    i7-4770
    Memory
    24 gb
    Monitor(s) Displays
    Benq 27
    Screen Resolution
    2560x1440
    Hard Drives
    256 gb Toshiba BG4 M.2 NVE SSB and 1 tb hdd
    PSU
    500w
    Case
    MT
    Cooling
    Dell factory
    Mouse
    Logitech wireless
    Keyboard
    Logitech wired
    Internet Speed
    still not telling
    Browser
    Firefox
    Antivirus
    Defender+MWB Premium

Feuer

Fatal Error
Member
VIP
Local time
11:31 AM
Posts
117
Location
Turkiye
OS
Windows 11 21H2 Home Single Language
add exit at the end
 

My Computer

System One

  • OS
    Windows 11 21H2 Home Single Language
    Computer type
    Laptop
    Manufacturer/Model
    Hometech ALFA400C
    CPU
    I'm ashamed to talk about it...
    Motherboard
    There is no such a God, I only know mother-Earth
    Memory
    3GB :(
    Graphics Card(s)
    on-board
    Sound Card
    on-board
    Monitor(s) Displays
    (s) is too ambitious for me
    Screen Resolution
    1920*1080
    Hard Drives
    Samsung SSD 860 EVO 250GB (SSD)
    Samsung MBG4GC 32GB (SSD)
    PSU
    I was very young when I last saw a PSU
    Case
    ...
    Cooling
    My coldness is enough to cool the computer
    Keyboard
    A broken and very clean keyboard
    Mouse
    Rat King
    Internet Speed
    Slowest internet connection in Europe
    Browser
    ChromePortable / TorBrowser
    Antivirus
    Biontech
    Other Info
    I can simply say that I took the red pill and I am not happy with it.

glasskuter

Well-known member
Pro User
VIP
Thread Starter
Local time
2:31 AM
Posts
2,900
Location
Paris in the Lone Star State of Texas
OS
Windows 11 Pro 22H2 22621.819

My Computers

System One System Two

  • OS
    Windows 11 Pro 22H2 22621.819
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 7080
    CPU
    i9-10900 10 core 20 threads
    Motherboard
    DELL 0J37VM
    Memory
    32 gb
    Graphics Card(s)
    none-Intel UHD Graphics 630
    Sound Card
    Integrated Realtek
    Monitor(s) Displays
    Benq 27
    Screen Resolution
    2560x1440
    Hard Drives
    256 m.2 2230-256+1 tb hdd
    PSU
    500w
    Case
    MT
    Cooling
    Dell Premium
    Keyboard
    Logitech wired
    Mouse
    Logitech wireless
    Internet Speed
    so slow I'm too embarrassed to tell
    Browser
    Firefox
    Antivirus
    Defender+MWB Premium
  • Operating System
    Windows 10 Pro 21H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 9020
    CPU
    i7-4770
    Memory
    24 gb
    Monitor(s) Displays
    Benq 27
    Screen Resolution
    2560x1440
    Hard Drives
    256 gb Toshiba BG4 M.2 NVE SSB and 1 tb hdd
    PSU
    500w
    Case
    MT
    Cooling
    Dell factory
    Mouse
    Logitech wireless
    Keyboard
    Logitech wired
    Internet Speed
    still not telling
    Browser
    Firefox
    Antivirus
    Defender+MWB Premium

SlicEnDicE

Well-known member
Power User
VIP
Local time
10:31 AM
Posts
1,205
Location
Finland
OS
Windows 11 Pro build 10.0.25247.1000 (Dev Channel)
Create a VBS Script:

Code:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "PATH TO YOUR BATCH SCRIPT" & Chr(34), 0
Set WshShell = Nothing

Replace PATH TO YOUR BATCH SCRIPT with the actual path to your file you wanna run.

Example:
1636302223642.png

Contens of writetext.bat:
1636302275703.png

Result every time I click the VBS file:
1636302321071.png

Contens of text.txt after a few clicks:
1636302369812.png

Never was any CMD windows displayed on my system. Try it out. 😄
 

My Computers

System One System Two

  • OS
    Windows 11 Pro build 10.0.25247.1000 (Dev Channel)
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo A485
    CPU
    Ryzen 7 2700U Pro
    Motherboard
    Lenovo
    Memory
    32GB
    Graphics Card(s)
    iGPU Vega 10
    Sound Card
    Realtek
    Monitor(s) Displays
    14" FHD (built-in) + 14" Lenovo Thinkvision M14t (touch+pen) + 32" Asus PB328
    Screen Resolution
    FHD + FHD + 1440p
    Hard Drives
    Intel 660p m.2 nVME PCIe3.0 x2 512GB
    PSU
    65W
    Keyboard
    Thinkpad
    Mouse
    Logitech MX Master 2S
    Internet Speed
    600/300Mbit
    Browser
    Edge (Chromium)
    Antivirus
    Windows Defender
    Other Info
    WSA: Installed
    SecureBoot: Enabled
    TPM2.0: Enabled
    AMD-V: Enabled
    VBS: Enabled
    HVCI: Enabled
  • Operating System
    Windows 10 Pro
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom
    CPU
    i7-7700k @4.8GHz
    Motherboard
    Asus PRIME Z270-A
    Memory
    32GB 2x16GB 2133MHz CL15
    Graphics card(s)
    EVGA GTX1080Ti FTW 11GB
    Sound Card
    Integrated
    Monitor(s) Displays
    32" 10-bit Asus PB328Q
    Screen Resolution
    WQHD 2560x1440
    PSU
    850W
    Case
    Fractal Design Define 7
    Cooling
    Noctua NH-D15 chromax.black
    Mouse
    Logitech MX Master 2S
    Keyboard
    Logitech G710+
    Internet Speed
    600/300Mbit
    Browser
    Edge (Cromium)
    Antivirus
    Windows Defender
    Other Info
    AC WiFi Card

glasskuter

Well-known member
Pro User
VIP
Thread Starter
Local time
2:31 AM
Posts
2,900
Location
Paris in the Lone Star State of Texas
OS
Windows 11 Pro 22H2 22621.819

My Computers

System One System Two

  • OS
    Windows 11 Pro 22H2 22621.819
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 7080
    CPU
    i9-10900 10 core 20 threads
    Motherboard
    DELL 0J37VM
    Memory
    32 gb
    Graphics Card(s)
    none-Intel UHD Graphics 630
    Sound Card
    Integrated Realtek
    Monitor(s) Displays
    Benq 27
    Screen Resolution
    2560x1440
    Hard Drives
    256 m.2 2230-256+1 tb hdd
    PSU
    500w
    Case
    MT
    Cooling
    Dell Premium
    Keyboard
    Logitech wired
    Mouse
    Logitech wireless
    Internet Speed
    so slow I'm too embarrassed to tell
    Browser
    Firefox
    Antivirus
    Defender+MWB Premium
  • Operating System
    Windows 10 Pro 21H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 9020
    CPU
    i7-4770
    Memory
    24 gb
    Monitor(s) Displays
    Benq 27
    Screen Resolution
    2560x1440
    Hard Drives
    256 gb Toshiba BG4 M.2 NVE SSB and 1 tb hdd
    PSU
    500w
    Case
    MT
    Cooling
    Dell factory
    Mouse
    Logitech wireless
    Keyboard
    Logitech wired
    Internet Speed
    still not telling
    Browser
    Firefox
    Antivirus
    Defender+MWB Premium

SlicEnDicE

Well-known member
Power User
VIP
Local time
10:31 AM
Posts
1,205
Location
Finland
OS
Windows 11 Pro build 10.0.25247.1000 (Dev Channel)
Awesome! Happy to help. 😄
 

My Computers

System One System Two

  • OS
    Windows 11 Pro build 10.0.25247.1000 (Dev Channel)
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo A485
    CPU
    Ryzen 7 2700U Pro
    Motherboard
    Lenovo
    Memory
    32GB
    Graphics Card(s)
    iGPU Vega 10
    Sound Card
    Realtek
    Monitor(s) Displays
    14" FHD (built-in) + 14" Lenovo Thinkvision M14t (touch+pen) + 32" Asus PB328
    Screen Resolution
    FHD + FHD + 1440p
    Hard Drives
    Intel 660p m.2 nVME PCIe3.0 x2 512GB
    PSU
    65W
    Keyboard
    Thinkpad
    Mouse
    Logitech MX Master 2S
    Internet Speed
    600/300Mbit
    Browser
    Edge (Chromium)
    Antivirus
    Windows Defender
    Other Info
    WSA: Installed
    SecureBoot: Enabled
    TPM2.0: Enabled
    AMD-V: Enabled
    VBS: Enabled
    HVCI: Enabled
  • Operating System
    Windows 10 Pro
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom
    CPU
    i7-7700k @4.8GHz
    Motherboard
    Asus PRIME Z270-A
    Memory
    32GB 2x16GB 2133MHz CL15
    Graphics card(s)
    EVGA GTX1080Ti FTW 11GB
    Sound Card
    Integrated
    Monitor(s) Displays
    32" 10-bit Asus PB328Q
    Screen Resolution
    WQHD 2560x1440
    PSU
    850W
    Case
    Fractal Design Define 7
    Cooling
    Noctua NH-D15 chromax.black
    Mouse
    Logitech MX Master 2S
    Keyboard
    Logitech G710+
    Internet Speed
    600/300Mbit
    Browser
    Edge (Cromium)
    Antivirus
    Windows Defender
    Other Info
    AC WiFi Card

wpcoe

Member
Local time
2:31 AM
Posts
68
Location
Mérida, México
OS
Windows 11 version 21H2 (OS Build 22000.469)
Does rundll32.exe powrprof.dll,SetSuspendState 0,1,0 still work? I wanted to create a simple shortcut, and several web pages for Win10 said that that command line from cmd.exe (as administrator) should sleep (or hibernate, if that's enabled) the computer, but it doesn't seem to do anything now in Win11.

I also tried creating a .bat file with the .vbs script as above, and again nothing seems to happen.
 

My Computers

System One System Two

  • OS
    Windows 11 version 21H2 (OS Build 22000.469)
    Computer type
    Laptop
    Manufacturer/Model
    HP Spectre X360 14
    CPU
    i7-1195G7
    Memory
    16GB
    Monitor(s) Displays
    external 24" Dell P2415Q
    Screen Resolution
    3840 x 2160 on external Dell, 3000 x 2000 on laptop screen
    Hard Drives
    1TB SSD with 32GB Optane cache
    Browser
    Vivaldi, Comodo Dragon, Edge
    Antivirus
    Avast (free version)
  • Operating System
    Windows 11 Pro, 21H2 (Build 22000.376)
    Computer type
    Tablet
    Manufacturer/Model
    Surface Pro 6
    CPU
    i7-8650U
    Memory
    16 GB
    Graphics card(s)
    iGPU (Intel® UHD Graphics 620)
    Monitor(s) Displays
    Dell P2415Q
    Screen Resolution
    3840 x 2160 on external Dell, 2736 x 1824 on SP6 screen
    Hard Drives
    512GB PCIe Gen 3 x2 SSD
    Browser
    Vivaldi, Comodo Dragon, Edge
    Antivirus
    Avast (free edition)

GadgetBuilder

Active member
Local time
3:31 AM
Posts
4
Location
Newtown, CT
OS
Windows 11 Pro
I'm running Win11 22H2 with Hibernate disabled. I have a shortcut on the desktop named "Sleep" with a target of :
C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState 0,1,0

Double clicking this shortcut puts the computer to sleep, no batch file needed.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro
    Computer type
    PC/Desktop
    Manufacturer/Model
    Home Built
    CPU
    Ryzen 5 5600G
    Motherboard
    Gigabyte B550 Aorus Pro AC
    Memory
    Ripjaws 2x8GB 3600
    Graphics Card(s)
    CPU internal
    Monitor(s) Displays
    Sharp LC-32D64U
    Screen Resolution
    1920 x 1080
    Hard Drives
    WD_Black SN770 250GB
    PSU
    Antec Earthwatts 380w
    Case
    Antec Sonata
    Cooling
    Scythe Mugen
    Keyboard
    Microsoft KU-0459
    Mouse
    Gaming Mouse (eBay)
    Internet Speed
    292/11
    Browser
    Firefox
    Antivirus
    Windows Defender
    Other Info
    Low noise, low power dissipation
  • Operating System
    Windows 10 Pro
    Computer type
    PC/Desktop
    Manufacturer/Model
    Home Built
    CPU
    AMD 5350
    Motherboard
    ASUS AM1I-A
    Memory
    8GB
    Monitor(s) Displays
    Dell
    Screen Resolution
    1920 x 1080
    Hard Drives
    Kingston 120GB SSD
    PSU
    Antec Earthwatts 380W
    Case
    Antec NSK 3180
    Cooling
    AMD
    Mouse
    Dell
    Keyboard
    Dell
    Internet Speed
    440/20
    Browser
    Firefox
    Antivirus
    Windows Defender

glasskuter

Well-known member
Pro User
VIP
Thread Starter
Local time
2:31 AM
Posts
2,900
Location
Paris in the Lone Star State of Texas
OS
Windows 11 Pro 22H2 22621.819
@Very good @GadgetBuilder That works too and is much easier. Thanks for the enlightenment.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 22H2 22621.819
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 7080
    CPU
    i9-10900 10 core 20 threads
    Motherboard
    DELL 0J37VM
    Memory
    32 gb
    Graphics Card(s)
    none-Intel UHD Graphics 630
    Sound Card
    Integrated Realtek
    Monitor(s) Displays
    Benq 27
    Screen Resolution
    2560x1440
    Hard Drives
    256 m.2 2230-256+1 tb hdd
    PSU
    500w
    Case
    MT
    Cooling
    Dell Premium
    Keyboard
    Logitech wired
    Mouse
    Logitech wireless
    Internet Speed
    so slow I'm too embarrassed to tell
    Browser
    Firefox
    Antivirus
    Defender+MWB Premium
  • Operating System
    Windows 10 Pro 21H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 9020
    CPU
    i7-4770
    Memory
    24 gb
    Monitor(s) Displays
    Benq 27
    Screen Resolution
    2560x1440
    Hard Drives
    256 gb Toshiba BG4 M.2 NVE SSB and 1 tb hdd
    PSU
    500w
    Case
    MT
    Cooling
    Dell factory
    Mouse
    Logitech wireless
    Keyboard
    Logitech wired
    Internet Speed
    still not telling
    Browser
    Firefox
    Antivirus
    Defender+MWB Premium

Dru2

Well-known member
Power User
VIP
Local time
3:31 AM
Posts
2,250
Location
Virginia
OS
Windows 11 Pro 22H2 (Build 22621.675)
I guess it must be tedious going to the Start menu and choosing Sleep :-)

Anyway, for those with keyboards with assignable keys, and the associated software, you can choose a button to put the PC to sleep. Here I have a Logitech Craft Keyboard with a "Lock" key, but instead I've assigned it to "Sleep" using the Logitech Options software...

2022-10-22_11-54-09.jpg

Now I can simply press that button and the PC will sleep. But, yes, I know the post is about creating a batch file, so. Just thought I'd throw this out for those who looking for other options (no pun intended).
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 22H2 (Build 22621.675)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom built
    CPU
    Intel i9-9900K
    Motherboard
    Gigabyte Aorus Z390 Xtreme
    Memory
    32G (4x8) DDR4 Corsair RGB Dominator Platinum (3600Mhz)
    Graphics Card(s)
    Radeon VII
    Sound Card
    Onboard (ESS Sabre HiFi using Realtek drivers)
    Monitor(s) Displays
    NEC PA242w (24 inch)
    Screen Resolution
    1920 x 1200
    Hard Drives
    5 Samsung SSD drives: 2X 970 NVME (512 & 1TB), 3X EVO SATA (2X 2TB, 1X 1TB)
    PSU
    EVGA Super Nova I000 P2 (1000 watt)
    Case
    Cooler Master H500M
    Cooling
    Corsair H115i RGB Platinum
    Keyboard
    Logitech Craft
    Mouse
    Logitech MX Master 3
    Internet Speed
    500mb Download. 11mb Upload
    Browser
    Microsoft Edge Chromium
    Antivirus
    Windows Security
    Other Info
    System used for gaming, photography, audiophile media center, work.
  • Operating System
    Win 10 Pro 22H2 (build 19045.2130)
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo ThinkPad Yoga X1
    CPU
    Intel i7-7600U
    Motherboard
    Intel
    Memory
    16igg
    Graphics card(s)
    Intel HD 620
    Sound Card
    Onboard
    Monitor(s) Displays
    14.0 WQHD OLED Touch
    Screen Resolution
    2560 x 1440
    Hard Drives
    1TB NVMe Drive (OEM)
    PSU
    laptop
    Case
    laptop
    Cooling
    Laptop cooling
    Mouse
    Logitech MX Anywhere 2S
    Keyboard
    Laptop
    Internet Speed
    100MB
    Browser
    Edge Chromium
    Antivirus
    Windows Security

Latest Support Threads

Top Bottom