PowerShell: Prevent screen saver, lock: Move mouse regularly

 

Alternatively, if you can't change the screen lock settings, you can move the mouse regularly, or have a script move the mouse. Originally published as an AutoIt script, I recreated the script with a few PowerShell lines. Anyone who copies the following commands into a PowerShell session will prevent the computer from locking the screen or starting the screensaver:

Add-Type -AssemblyName System.Windows.Forms
while ($true)
{
  $Pos = [System.Windows.Forms.Cursor]::Position
  [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(($pos.X+1), ($pos.Y+1))
  [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($pos.X, $pos.Y)
  Start-Sleep -Seconds 60
}

To run: Copy content to clipboard and:

The script moves the mouse one pixel and back every 60 seconds.

positive Bewertung({{pro_count}})
Rate Post:
{{percentage}} % positive
negative Bewertung({{con_count}})

THANK YOU for your review!

Questions / Comments