Jump to content

Automating Windows SteadyState


Cyri
 Share

Recommended Posts

I'm working with Windows SteadyState and there is no fully unattended way to configure it. Sounds like a job for AutoIT. The main window has three link(hotspots) for "Set Computer Restrictions", "Schedule Software Updates", and "Protect the Hard Disk". See screenshot below for details.

post-27559-1236091695_thumb.jpg

My problem is that I can't seem to get ControlClick to click them. Here is my code:

Opt("WinTitleMatchMode",4)

;Set variables
$MainWin = "Windows SteadyState v2.5"
$HelpWin = "Windows SteadyState"

; Run Windows SteadyState UI
If FileExists("C:\Program Files\Windows SteadyState\SCTUI.exe") Then
    Run("C:\Program Files\Windows SteadyState\SCTUI.exe")
EndIf

; Close help file
WinWait("[TITLE:" & $MainWin & "]","",20)
If WinExists("[TITLE:" & $HelpWin & "; CLASS:HH Parent]") Then
    WinClose("[TITLE:" & $HelpWin & "; CLASS:HH Parent]")
EndIf

; Open Computer Restrictions
$hWND = WinGetHandle ("[TITLE:" & $MainWin & "]")
$hControl = ControlGetHandle($hWND,"","[CLASS:#32770; INSTANCE:2]")
ControlClick($hWND,"",$hControl)

I have verified that the control handle is being assigned to $hControl, but it won't click. I'm wondering if these controls are different. Like maybe these screens are HTML behind the scenes.

I've found two workarounds which are MouseClick and doing a sendkey solution with Tab and Space to select the control, but neither are ideal. Anyone have another idea?

Edited by Cyri
Link to comment
Share on other sites

I'm working with Windows SteadyState and there is no fully unattended way to configure it. Sounds like a job for AutoIT. The main window has three link(hotspots) for "Set Computer Restrictions", "Schedule Software Updates", and "Protect the Hard Disk". See screenshot for details.

Windows SteadyState (main screen)

My problem is that I can't seem to get ControlClick to click them. Here is my code:

Opt("WinTitleMatchMode",4)

;Set variables
$MainWin = "Windows SteadyState v2.5"
$HelpWin = "Windows SteadyState"

; Run Windows SteadyState UI
If FileExists("C:\Program Files\Windows SteadyState\SCTUI.exe") Then
    Run("C:\Program Files\Windows SteadyState\SCTUI.exe")
EndIf

; Close help file
WinWait("[TITLE:" & $MainWin & "]","",20)
If WinExists("[TITLE:" & $HelpWin & "; CLASS:HH Parent]") Then
    WinClose("[TITLE:" & $HelpWin & "; CLASS:HH Parent]")
EndIf

; Open Computer Restrictions
$hWND = WinGetHandle ("[TITLE:" & $MainWin & "]")
$hControl = ControlGetHandle($hWND,"","[CLASS:#32770; INSTANCE:2]")
ControlClick($hWND,"",$hControl)

I have verified that the control handle is being assigned to $hControl, but it won't click. I'm wondering if these controls are different. Like maybe these screens are HTML behind the scenes.

I've found two workarounds which are MouseClick and doing a sendkey solution with Tab and Space to select the control, but neither are ideal. Anyone have another idea?

There are 3 different advanced classes for those controls. They are:

Residing within #32770

Class: Static; Instance: 8 (Set Computer Restrictions)

Class: Static; Instance: 13 (Schedule Software Updates)

Class: Static; Instance: 20 (Protect the Hard Disk)

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Link to comment
Share on other sites

There are 3 different advanced classes for those controls. They are:

Residing within #32770

Class: Static; Instance: 8 (Set Computer Restrictions)

Class: Static; Instance: 13 (Schedule Software Updates)

Class: Static; Instance: 20 (Protect the Hard Disk)

Thanks for the info. I'll try that tomorrow at the office. How did you come across these instances? I was using the AutoIT window Info tool and came up with instances 2, 3, and 11 as possibilities for "Set Computer Restrictions", but I never came across instance 8.

Link to comment
Share on other sites

Actually, those instances you specified are merely the static text controls in the window and not the actual buttons themselves. I did find out that if you move the mouse over one of the buttons and then do a ControlClick it works. According to uuSpy it shows a WM_HITTEST being performed to verify whether the mouse is over one of the buttons which is why the ControlClick requires the mouse be over the button in order for it to work. Here is a sample of the code I'm using now to flip between those initial three buttons. Not perfect since it relies on MouseMove, but better than what I was doing. I'll keep digging to see if this can be automated without the MouseMove.

#Include <WinAPI.au3>

Opt("WinTitleMatchMode",4)
Opt("WinWaitDelay",1000); Without this the ControlGetHandle doesn't get the handle to the control, looks like a timing issue related to how the form is drawn.
Opt("MouseCoordMode",2)

;Set variables
$MainWin = "Windows SteadyState v2.5"
$HelpWin = "Windows SteadyState"
$SetCompRes = 2
$SchSoftUpd = 4
$ProtectHD = 6

; Run Windows SteadyState UI
If FileExists("C:\Program Files\Windows SteadyState\SCTUI.exe") Then
    Run("C:\Program Files\Windows SteadyState\SCTUI.exe")
EndIf

; Initialize window, close help file (if necessary)
WinWait("[TITLE:" & $MainWin & "]","",10)
If WinExists("[TITLE:" & $MainWin & "]") Then
    $hWND = WinGetHandle("[TITLE:" & $MainWin & "]")
Else
    Exit
EndIf
If WinExists("[TITLE:" & $HelpWin & "; CLASS:HH Parent]") Then
    WinClose("[TITLE:" & $HelpWin & "; CLASS:HH Parent]")
EndIf

; Go to Set Computer Restrictions
ChangeScreen($hWND, $SetCompRes)

Func ChangeScreen($hWND, $CI)
    $hClass = _WinAPI_GetClassName($hWND)
    $hControl = ControlGetHandle($hWND,"","[CLASS:" & $hClass & "; INSTANCE:" & $CI & "]")
    $Pos = ControlGetPos($hWND,"",$hControl)
    WinActivate($hWND)
    BlockInput(1)
    MouseMove($Pos[0],$Pos[1])
    ControlClick($hWND, "", $hControl)
    BlockInput(0)
EndFunc
Edited by Cyri
Link to comment
Share on other sites

Just out of curiosity, why do you block input and then ControlClick, that works with hidden windows too.

Because of the MouseMove. The ControlClick won't work unless the mouse is over it. If I don't block input theres a chance someone could move the mouse off the control and the ControlClick would fail. Unless the time between the MouseMove and ControlClick commands is so fast that isn't possible? I don't know, but to be on the safe side I blocked input.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...