Last active
August 29, 2015 13:59
-
-
Save JonasGroeger/10512890 to your computer and use it in GitHub Desktop.
Shows a dialog to shut down the computer in a specified time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --------------------------------------------------------------------- | |
# 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