PowerShell Script to Prevent Your Machine From Logging You Out or Sleeping While You Do Other Things

In certain environments, my development machine does not have access to the interwebs. I have to use a separate machine that is connected to the outside world to lookup a snippet or research a deeper issue. If I don’t think to tap the space bar at least every four minutes and 59 seconds, I have to re-authenticate to continue development. Then those dozen or so characters I’ve had to memorize interrupt me (Squirrel!) from the issue at hand; worse if I fat-finger the input. So here is a PowerShell script that does the mindless key tapping for me:

param($numKeyTaps = 90)
$wsShell = New-Object -com "Wscript.Shell"
for ($i = 0; $i -lt $numKeyTaps; $i++) {
Start-Sleep -Seconds 360
$wsShell.sendkeys("{NUMLOCK}")
Write-Host "Tapped Numlock key"
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s