Prevent screensaver from disturbing my presentations.

Most companies have GPO settings that enforces a company wide screensaver policy, in my case the screensaver kicks in after 5 min.

5 Min is a very short time, when you are doing presentations or showing video content, so I decided to create a little AutoIT script to move the mouse 1 pixel after 4 min and 59 sec.

I decided to create a small tray icon, where I can choose how many minutes I want it to run for, and the icon changes in color, when the “screensaver free” time is running out.

[sourcecode lang=”bash”]

Opt(“TrayOnEventMode”,1)
Opt(“TrayAutoPause”,0)
Opt(“TrayMenuMode”,1)   ; Default tray menu items (Script Paused/Exit) will not be shown.
HotKeySet(“^!q”, “_ExitLoop”)

$DisableScreenSaver    = TrayCreateMenu(“Disable Screensaver”)

TrayCreateItem(“”)
TrayCreateItem(“About”)
TrayItemSetOnEvent(-1, “DoAbout”)
TrayCreateItem(“”)
TrayCreateItem(“Exit (To exit pres CTRL-ALT-q)”)
TrayItemSetOnEvent(-1, “DoExit”)

TrayCreateItem(“15 Min”, $DisableScreenSaver)
TrayItemSetOnEvent(-1, “DisableScreenSaver15″)
TrayCreateItem(“30 Min”, $DisableScreenSaver)
TrayItemSetOnEvent(-1, “DisableScreenSaver30″)
TrayCreateItem(“45 Min”, $DisableScreenSaver)
TrayItemSetOnEvent(-1, “DisableScreenSaver45″)
TrayCreateItem(“60 Min”, $DisableScreenSaver)
TrayItemSetOnEvent(-1, “DisableScreenSaver60″)
TrayCreateItem(“90 Min”, $DisableScreenSaver)
TrayItemSetOnEvent(-1, “DisableScreenSaver90″)
TraySetState()
TraySetIcon(“shell32.dll”,251)

While 1
Sleep(1000)
WEnd

Func _ExitLoop()
Exit 0
EndFunc

Func getpos()
$x = MouseGetPos(0)
$y = MouseGetPos(1)
; MsgBox ( 0, “MSG”, “MousePos: “& $x &”, ” & $y , 1 )
MouseMove($x,$y+1,1)
endfunc

Func DisableScreenSaver15()
For $i = 1 to 3 Step 1
If $i = 1 then TraySetIcon(“wpdshext.dll”,714)
If $i = 2 then TraySetIcon(“wpdshext.dll”,711)
If $i = 3 then TraySetIcon(“wpdshext.dll”,710)
Sleep(299000)
GetPos()
Next
Msgbox(64,”Time is Up!”,”Time without screensaver is up!”)
TraySetIcon(“shell32.dll”,251)
EndFunc

Func DisableScreenSaver30()
$begin = TimerInit()
For $i = 1 to 6 Step 1
If $i = 1 then TraySetIcon(“wpdshext.dll”,714)
If $i = 2 then TraySetIcon(“wpdshext.dll”,713)
If $i = 3 then TraySetIcon(“wpdshext.dll”,712)
If $i = 4 then TraySetIcon(“wpdshext.dll”,711)
If $i = 6 then TraySetIcon(“wpdshext.dll”,710)

Sleep(299000)

GetPos()
Next

Msgbox(64,”Time is Up!”,”Time without screensaver is up!”)
TraySetIcon(“shell32.dll”,251)
EndFunc

Func DisableScreenSaver45()
For $i = 1 to 9 Step 1
If $i = 1 then TraySetIcon(“wpdshext.dll”,714)
If $i = 4 then TraySetIcon(“wpdshext.dll”,713)
If $i = 6 then TraySetIcon(“wpdshext.dll”,712)
If $i = 8 then TraySetIcon(“wpdshext.dll”,711)
If $i = 9 then TraySetIcon(“wpdshext.dll”,710)
Sleep(299000)
GetPos()
Next
Msgbox(64,”Time is Up!”,”Time without screensaver is up!”)
TraySetIcon(“shell32.dll”,251)
EndFunc

Func DisableScreenSaver60()
For $i = 1 to 12 Step 1
If $i = 1 then TraySetIcon(“wpdshext.dll”,714)
If $i = 6 then TraySetIcon(“wpdshext.dll”,713)
If $i = 8 then TraySetIcon(“wpdshext.dll”,712)
If $i = 11 then TraySetIcon(“wpdshext.dll”,711)
If $i = 12 then TraySetIcon(“wpdshext.dll”,710)
Sleep(299000)
GetPos()
Next
Msgbox(64,”Time is Up!”,”Time without screensaver is up!”)
TraySetIcon(“shell32.dll”,251)
EndFunc

Func DisableScreenSaver90()
For $i = 1 to 18 Step 1
If $i = 1 then TraySetIcon(“wpdshext.dll”,714)
If $i = 6 then TraySetIcon(“wpdshext.dll”,713)
If $i = 12 then TraySetIcon(“wpdshext.dll”,712)
If $i = 17 then TraySetIcon(“wpdshext.dll”,711)
If $i = 18 then TraySetIcon(“wpdshext.dll”,710)
Sleep(299000)
GetPos()
Next
Msgbox(64,”Time is Up!”,”Time without screensaver is up!”)
TraySetIcon(“shell32.dll”,251)
EndFunc

Func DoAbout()
Msgbox(64,”About:”,”Tool by Claus T. Nielsen”)
EndFunc

Func DoExit()
Exit
EndFunc

[/sourcecode]

In order to make it look good, you need the file wpdshext.dll, which is available in Vista… Otherwise you will not have the changing icon, the program will work fine though.

Not pretty code, but it does what it is supposed to.

Read More

MSTSC Util

A while back I needed to connect to different servers quite often via mstsc, and a lot of the times I needed a console connection to the specific server, so I decided to write a small app, so I did not have to type Mstsc /v:server /console all the time.

I decided to make a small AutoIT app, that would dock in the systray.
Systray icon

What it does is, it reads a list of servers from an .ini file, you need to prepopulate the list with the servers in your own environment like this.

Servers.INI

So what it ends up looking like in “production” is something like this…

You can download the compiled app here…
Flex Console connect app by Xenophane

For the paranoid I will attach the AutoIT source code, so you can compile it your self :)


#Include

Opt("TrayOnEventMode",1)
Opt("TrayAutoPause",0)
Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.
Global $server[100][3]

$Console = TrayCreateMenu("Console Connect")
$Regular = TrayCreateMenu("Regular Connect")

$data = IniReadSection ( @ScriptDir&"\servers.ini", "servers" )

;~ For $i = 1 To $data[0][0]
;~ MsgBox(4096, "", "Key: " & $data[$i][2] & @CRLF & "Value: " & $data[$i][1])
;~ Next

$server[0][0] = $data[0][0]
For $i = 1 to $data[0][0]
$server[$i][0] = TrayCreateItem($data[$i][0], $Console)
TrayItemSetOnEvent(-1, "ServerConsole")
$server[$i][1] = TrayCreateItem($data[$i][0], $Regular)
TrayItemSetOnEvent(-1, "ServerRegular")
$server[$i][2] = $data[$i][1]
Next

TrayCreateItem("")
TrayCreateItem("About")
TrayItemSetOnEvent(-1, "DoAbout")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "DoExit")

TraySetState()

While 1
Sleep(100)
WEnd

Func DoAbout()
Msgbox(64,"About:","Tool by Claus T. Nielsen")
EndFunc

Func DoExit()
Exit
EndFunc

Func ServerConsole()
For $i = 1 to $server[0][0]
If $server[$i][0] = @TRAY_ID Then
Run("mstsc -v:"&$server[$i][2]&" /F -console")
ExitLoop
EndIf
Next
EndFunc

Func ServerRegular()
For $i = 1 to $server[0][0]
If $server[$i][1] = @TRAY_ID Then
Run("mstsc -v:"&$server[$i][2]&" ")
ExitLoop
EndIf
Next
EndFunc


Remember that the /console switch has been deprecated in Vista SP1, and replaced by the /admin switch, the above code does not reflect this change currently, but it is very easily changed.

Read More