PPowerShell Script (Save as ShutdownPC.ps1
)
powershell# Shutdown PC script
Stop-Computer -Force
powershell# Shutdown PC script Stop-Computer -Force
How to Run It
- Open PowerShell as Administrator (right-click Start > Windows PowerShell (Admin)).
- Navigate to the script's directory:
cd "C:\Path\To\Your\Script"
. - Execute:
.\ShutdownPC.ps1
.
- Open PowerShell as Administrator (right-click Start > Windows PowerShell (Admin)).
- Navigate to the script's directory:
cd "C:\Path\To\Your\Script"
. - Execute:
.\ShutdownPC.ps1
.
One-Liner Alternative
If you just want to run it directly in PowerShell (as Admin):
powershellStop-Computer -Force
For a delayed shutdown (e.g., 30 seconds), use:
powershellStop-Computer -Force -Wait -For PowerOff -Timeout 30
If you need to restart instead, replace with Restart-Computer -Force
.
![]()
shutdown pc with run bat
BLACKBOXAI![]()
Here's a simple Windows batch file (.bat) script to shut down your PC immediately. Warning: This will force a shutdown without saving open files or prompting for confirmation. Run it only if you're sure, and test on a non-critical machine if possible.
If you just want to run it directly in PowerShell (as Admin):
powershellStop-Computer -Force
For a delayed shutdown (e.g., 30 seconds), use:
powershellStop-Computer -Force -Wait -For PowerOff -Timeout 30
If you need to restart instead, replace with Restart-Computer -Force
.
shutdown pc with run bat
Here's a simple Windows batch file (.bat) script to shut down your PC immediately. Warning: This will force a shutdown without saving open files or prompting for confirmation. Run it only if you're sure, and test on a non-critical machine if possible.
Batch Script (Save as ShutdownPC.bat
)
Create a new text file, paste the following code, and save it with a .bat
extension (e.g., ShutdownPC.bat
):
batch@echo off
echo Shutting down PC in 5 seconds... Press Ctrl+C to cancel.
timeout /t 5 /nobreak >nul
shutdown /s /f /t 0
/s
: Shuts down the PC./f
: Forces running applications to close./t 0
: Sets the timeout to 0 seconds (immediate after the delay).- The
timeout
adds a 5-second grace period for you to cancel (press Ctrl+C).
Create a new text file, paste the following code, and save it with a .bat
extension (e.g., ShutdownPC.bat
):
batch@echo off echo Shutting down PC in 5 seconds... Press Ctrl+C to cancel. timeout /t 5 /nobreak >nul shutdown /s /f /t 0
/s
: Shuts down the PC./f
: Forces running applications to close./t 0
: Sets the timeout to 0 seconds (immediate after the delay).- The
timeout
adds a 5-second grace period for you to cancel (press Ctrl+C).
How to Run It
- Save the file to a convenient location (e.g., Desktop).
- Right-click the
.bat
file and select Run as administrator (important for shutdown privileges).- Or, open Command Prompt as Administrator (right-click Start > Command Prompt (Admin) or Terminal (Admin)), navigate to the file's directory with
cd "C:\Path\To\Your\Script"
, and run ShutdownPC.bat
.
- Save the file to a convenient location (e.g., Desktop).
- Right-click the
.bat
file and select Run as administrator (important for shutdown privileges).- Or, open Command Prompt as Administrator (right-click Start > Command Prompt (Admin) or Terminal (Admin)), navigate to the file's directory with
cd "C:\Path\To\Your\Script"
, and runShutdownPC.bat
.
- Or, open Command Prompt as Administrator (right-click Start > Command Prompt (Admin) or Terminal (Admin)), navigate to the file's directory with
One-Liner Alternative
If you just want to run it directly in Command Prompt (as Admin) without a file:
cmdshutdown /s /f /t 0
If you just want to run it directly in Command Prompt (as Admin) without a file:
cmdshutdown /s /f /t 0
Variations
Delayed Shutdown (e.g., 30 seconds, with cancel option):
batch@echo off
shutdown /s /f /t 30
echo PC will shut down in 30 seconds. To cancel, run: shutdown /a
- To cancel a pending shutdown: Open Command Prompt as Admin and run
shutdown /a
.
Restart Instead: Replace /s
with /r
in the command (e.g., shutdown /r /f /t 0
).
If you're on a different OS (e.g., Linux/Mac), let me know for alternatives. Always back up important work before using shutdown scripts!
Delayed Shutdown (e.g., 30 seconds, with cancel option):
batch@echo off shutdown /s /f /t 30 echo PC will shut down in 30 seconds. To cancel, run: shutdown /a
- To cancel a pending shutdown: Open Command Prompt as Admin and run
shutdown /a
.
- To cancel a pending shutdown: Open Command Prompt as Admin and run
Restart Instead: Replace
/s
with/r
in the command (e.g.,shutdown /r /f /t 0
).
If you're on a different OS (e.g., Linux/Mac), let me know for alternatives. Always back up important work before using shutdown scripts!
0 komentar:
Posting Komentar