Skip to content

Instantly share code, notes, and snippets.

@JonasGroeger
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonasGroeger/10512890 to your computer and use it in GitHub Desktop.
Save JonasGroeger/10512890 to your computer and use it in GitHub Desktop.
Shows a dialog to shut down the computer in a specified time.
@echo off
setlocal
REM Generic .bat file to launch .ps1 files.
REM Name the .bat file like the .ps1 file and you are done.
set this_file_no_extension=%~n0
set ps1_file=%this_file_no_extension%.ps1
powershell.exe -ExecutionPolicy Bypass -NoLogo -WindowStyle Hidden -NoProfile -File %ps1_file%
endlocal
# ---------------------------------------------------------------------
# Script: Shutdown.ps1
# Author: Jonas Gröger <jonas.groeger@gmail.com>
# Date: 12.04.2014
# Keywords: Shutdown, Timer, Minutes
# Comments: Reads a number of minutes from the command line and shuts
# down after that time.
# ---------------------------------------------------------------------
$minutes = 0
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
do {
$input = [Microsoft.VisualBasic.Interaction]::InputBox('In how many minutes should I shut down?', "Shutdown", 0)
# User pressed cancel
if (!$input) {
Exit
}
$no_number = ![int]::TryParse($input, [ref]$minutes)
$below_zero = $minutes -lt 0
} while($no_number -or $below_zero)
$seconds = $minutes * 60
shutdown /s /f /t $seconds /c "Shutting down the computer in $seconds seconds ($minutes minutes)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment