Skip to content

Instantly share code, notes, and snippets.

@paveltimofeev
Last active September 10, 2015 08:56
Show Gist options
  • Save paveltimofeev/bea7074a0972e5d41a7b to your computer and use it in GitHub Desktop.
Save paveltimofeev/bea7074a0972e5d41a7b to your computer and use it in GitHub Desktop.
Locking PC after some minutes (powershell script / WIN)
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 }
@paveltimofeev
Copy link
Author

Lock PC every 1.5 hours for 5 min

while( $true )
{
    Wait-For 90 { Lock-PC }
    1..5 | % { Wait-For 1 { Lock-PC } } 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment