Jump to content

winwait() for window text using regex?


Recommended Posts


To automate MAK activation on different localization versions of Win7 and above I'd like to winwait for a set of possible window text strings.

The script below works fine, when I have dedicated versions for each localisation's language. I currently can't see, how to wait for a set of possible text strings. Opt("WinTitleMatchMode", 3) seems to target *TITLES* only, not the text of a window?


$WHS = "Windows Script Host"
$Btn = "Button1"
$MAK = "ABCDE-12345-ABCDE-12345-ABCDE"
$LicVer= "Windows 7 Enterprise (MAK)"

Dim $SlmgrParams[4][2] = [[3], _
        ["/upk", "(?i)(Der Product Key wurde erfolgreich deinstalliert.|Uninstalled product key successfully|Error: product key not found)"], _
        ["/ipk " & $MAK, "(?i)(Der Product Key " & $MAK  & " wurde erfolgreich installiert|installed successfully)"], _
        ["/ato", "(?i)(Das Produkt wurde erfolgreich aktiviert|activated successfully)"]]

$msgtxt = $LicVer & ", install, activate:" & @CRLF & @CRLF


For $i = 1 To $SlmgrParams[0][0]
    ShellExecute("slmgr.vbs", $SlmgrParams[$i][0], @TempDir, "", @SW_SHOW)
    If WinWait($WHS, $SlmgrParams[$i][1], 30) Then ; < ------------------------- howto wait for window text using RegEx?
        sleep(1000) ; damit man das kurz lesen kann...
        ControlClick($WHS, $SlmgrParams[$i][1], $Btn)
        ToolTip($SlmgrParams[$i][0], 30, 30, "WHS Result Window doesn't show up, waiting...")
        While WinExists($WHS)
            ToolTip($SlmgrParams[$i][0], 30, 30, "check WHS Result Window, then continue!")
        ToolTip("Trying to proceed", 30, 30, "Windows  Aktivation")

if $Problem Then
    MsgBox(48,$LicVer & " Aktivierung","Propably " & $Problem & " errors occured while trying to activate this installation!")
    MsgBox(0,$LicVer & " Aktivierung","This Windows installation should be activated now.",30)

Any suggestion appreciated, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

You can regex-check the content of a window, here is an example (try it using notepad)

Dim $SlmgrParams[4][2] = [[3], _
        ["/upk", "(?i)(deinstalliert|Uninstalled|Error)"], _
        ["/ipk ", "(?i)( installiert|successfully)"], _
        ["/ato", "(?i)(aktiviert|activated)"]]

While 1
Local $var = WinList()
For $i = 1 To $var[0][0]
    If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
      For $k = 1 To $SlmgrParams[0][0]
         $res = StringRegExp(WinGetText($var[$i][1]), $SlmgrParams[$k][1], 1)
         If IsArray($res) Then Exit MsgBox(0, "", $var[$i][0] &@crlf& $res[0])

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
        Return 0
EndFunc   ;==>IsVisible

This works for detection, for WinWait+timeout adding a timer inside the loop should to the trick

Edited by mikell
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

  • Recently Browsing   0 members

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