Solved Batch file to put computer to sleep


glasskuter

Well-known member
Pro User
VIP
Local time
4:03 AM
Posts
2,532
Location
The Lone Star State of Texas
OS
Windows 11 Pro 22H2 22621.382
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.382
    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
Local time
12:03 PM
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
4:03 AM
Posts
2,532
Location
The Lone Star State of Texas
OS
Windows 11 Pro 22H2 22621.382

My Computers

System One System Two

  • OS
    Windows 11 Pro 22H2 22621.382
    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
12:03 PM
Posts
1,060
Location
Finland
OS
Windows 11 Pro build 10.0.25206.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.25206.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
4:03 AM
Posts
2,532
Location
The Lone Star State of Texas
OS
Windows 11 Pro 22H2 22621.382

My Computers

System One System Two

  • OS
    Windows 11 Pro 22H2 22621.382
    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
12:03 PM
Posts
1,060
Location
Finland
OS
Windows 11 Pro build 10.0.25206.1000 (Dev Channel)
Awesome! Happy to help. 😄
 

My Computers

System One System Two

  • OS
    Windows 11 Pro build 10.0.25206.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
4:03 AM
Posts
67
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)

Latest Tutorials

Top Bottom