# 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: 129RQW
# license: CC0
# x-poshcode-id: 2902
# x-archived: 2011-08-22T02:13:01
# x-published: 2011-08-07T17:34: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(".")
}