Skip to content

Instantly share code, notes, and snippets.

@duchenpaul
Last active October 27, 2021 05:14
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 duchenpaul/332dc04c66b424b1abfaaf4f3268ba52 to your computer and use it in GitHub Desktop.
Save duchenpaul/332dc04c66b424b1abfaaf4f3268ba52 to your computer and use it in GitHub Desktop.
A simple vbs to prevent your PC from policy screen lock
Add-Type -AssemblyName System.Windows.Forms
New-Variable -name INTERVAL -Value (60 * 2) -Option Constant -Description 'for 5mins lock default'
get-date
echo `start`
while ($true) {
$key = '{SCROLLLOCK}'
get-date
echo "press key $key`n"
try {
[System.Windows.Forms.SendKeys]::SendWait($key)
[System.Windows.Forms.SendKeys]::SendWait($key)
}
catch {
Write-Host "An error occurred:"
Write-Host $_
Write-Host $_.ScriptStackTrace
}
sleep -s $INTERVAL
}
Dim objResult
Set objShell = WScript.CreateObject("WScript.Shell")
Do While True
Wscript.Sleep(3000)
objResult = objShell.sendkeys("{SCROLLLOCK}")
Wscript.Sleep(100)
objResult = objShell.sendkeys("{SCROLLLOCK}")
Wscript.Sleep(100)
objResult = objShell.sendkeys("{SCROLLLOCK}")
Wscript.Sleep(100)
objResult = objShell.sendkeys("{SCROLLLOCK}")
Loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment