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!

Publication: 2022-12-02 from Bernhard | Übersetzung Deutsch |🔔 | Comments:0

Using PowerShell to set file system permissions: ACL | PowerShell | Restore file version history

Top articles in this section


PowerShell Log-Files: Logging into a textfile - write to file

Log files in PowerShell can be created via the Out-File command, via a custom function, or via PowerShell's built-in Transcript.


PowerShell TCP Listener

PowerShell uses the following commands to open a socket on a specific port via System.NET:


PowerShell: File attributes: Change date - without any tools.

As an alternative to special programs, the date of a file or folder can also be changed with PowerShell. 

Questions / Comments