Last active
September 10, 2015 08:56
-
-
Save paveltimofeev/bea7074a0972e5d41a7b to your computer and use it in GitHub Desktop.
Locking PC after some minutes (powershell script / WIN)
This file contains hidden or 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
cls | |
function Wait-For | |
{ | |
param( $minutes, $callback ) | |
$untill = (Get-Date).AddMinutes($minutes) | |
Wait-Untill $untill.Hour $untill.Minute $callback | |
} | |
function Wait-Untill | |
{ | |
param( $wait_Hour, $wait_Minute, $callback ) | |
"Wait untill $($wait_Hour):$($wait_Minute)" | |
$now = Get-Date | |
while($now.Hour -ne $wait_Hour -or $now.Minute -ne $wait_Minute) | |
{ | |
$now = Get-Date | |
Sleep -s 1 | |
} | |
& $callback | |
} | |
function Lock-PC | |
{ | |
rundll32.exe user32.dll,LockWorkStation | |
} | |
Wait-For 30 { Lock-PC } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lock PC every 1.5 hours for 5 min