Useful Script Number 2 - Move the Task Sequence Window

Have you ever created a build and had to pop up a message to the user/technician? - or had to start an HTA application to request some kind of user input during the build or deployment process? If you have then you will know that the task sequence window sits centre screen and everything else pops up behind. This is because the task sequence windows is fixed to the top of the Z-order so that no other window can overlap it...

Recently I had to create an DVD based deployment for a customer where I wrote an HTA application that prompted the user to switch DVDs. I hit this issue where my app was popping up behind the task sequence window and users were missing the prompt - so I set about developing a solution - and the solution I came up with was to move the task sequence window to the top left corner of the screen every time the task sequence starts - I soon found that it wasn't as simple as it initially sounded....

I set about creating a script in Autoit (http://www.autoitscript.com/) to move the window to the correct co-ordinates based on current screen resolution. I like to use Autoit for window manipulation tasks as it has a whole raft of inbuilt functions for automating desktop tasks - which usually makes it easier and quicker than writing the equivalent in VB script.

The Autoit code is listed below:

#NoTrayIcon

;zCFG-MoveTaskWindow
;Version 2.0 March 2008
;Reruns itself and returns - only works when compiled

If $CmdLine[0] = 0 Then
; Rerun ourself and let this copy return to the task sequencer
Run('"' & @AutoItExe & '" rerun')
Exit
EndIf

Sleep(5000) ; Time for the first script to return
If WinExists("Systems Management Server") Then
$size = WinGetPos("Systems Management Server")
Mousemove($size[0]+50, $size[1]+50)
MouseClick("left")
WinMove("Systems Management Server", "", 0, 0)
Exit
Else
Exit
EndIf

The first line #NoTrayIcon stops the Autoit icon appearing in the system tray when the script runs. The next section:

If $CmdLine[0] = 0 Then
; Rerun ourself and let this copy return to the task sequencer
Run('"' & @AutoItExe & '" rerun')
Exit
EndIf

configures the script to re-start itself after returning control to the task sequencer (i will explain why later in the post) before running the code to carry out the window move - having access to Autoit creator and fellow UK MCS consultant Jon Bennett really helps in these situations :-) and Jon came up with this re-spawning code.

The final section:

Sleep(5000) ; Time for the first script to return
If WinExists("Systems Management Server") Then
$size = WinGetPos("Systems Management Server")
Mousemove($size[0]+50, $size[1]+50)
MouseClick("left")
WinMove("Systems Management Server", "", 0, 0)
Exit
Else
Exit
EndIf

causes the script to pause for 5 seconds before looking for the existence of the task sequence window (using the Autoit function WinExists). The title of the windows is Systems Management Server, so if found the script gets its position (using the Autoit function WinGetPos). The script then move the mouse to the location of the window +50 pixels on each axis so that the mouse pointer is inside the task sequence window - it then clicks (Autoit function MouseClick) to select the window before the WinMove function moves it to the top left of the screen

The reason for re-spawning the script is to return control to the task sequence, which in turn means that the compiled executable that Autoit creates from this script can be added to the task sequencer in the same way that any other script is run:

1

The script only works when it is compiled so i have added the script (.au3 file) and the compiled Autoit executable (.exe) to the download location below:

This post was contributed by Richard Smith a Senior Consultant with Microsoft Services, UK.