PoshCode Archive  Artifact [882c158b48]

Artifact 882c158b4884e36fb7139d106b9fcf75da736f93778971980c47176fc477e2bb:

  • File Prevent-Screensaver.ps1 — part of check-in [aaf865c51f] at 2018-06-10 13:16:44 on branch trunk — Simulate user activity to prevent desktop lock or screensaver for specified period of time (user: Dmitry Sotnikov size: 1352)

# encoding: ascii
# api: powershell
# title: Prevent-Screensaver
# description: Simulate user activity to prevent desktop lock or screensaver for specified period of time
# version: 0.1
# type: script
# author: Dmitry Sotnikov
# license: CC0
# x-poshcode-id: 2901
# x-derived-from-id: 2902
# x-archived: 2011-09-18T11:50:22
# x-published: 2011-08-07T17:30:00
#
#
#########################################################
# Prevent-Screensaver
#########################################################
# This script "presses" a keyboard key every minute
# for specified number of minutes which makes
# Windows "think" you are at your desktop
# so the screensaver does not start and the desktop
# does not get locked. 
#########################################################
# Usage:
# & c:\filepath\Prevent-Screensaver.ps1 -Minutes 120
# Makes the script press "." for 120 minutes.
# Start notepad or another app and put focus there
# to see the dots appear and prevent beeping
########################################################
# (c) Dmitry Sotnikov
# http://dmitrysotnikov.wordpress.com
########################################################

param($minutes = 60)

$myshell = New-Object -com "Wscript.Shell"

for ($i = 0; $i -lt $minutes; $i++) {
  Start-Sleep -Seconds 60
  $myshell.sendkeys(".")
}