Jump to content

Unable to RunWait after WinWait


Armis
 Share

Recommended Posts

Hi,

I'm trying to close some error windows that pop up during a program installation using AutoIt and then, if the pop up occurred, launch a command to finalize the installation correctly. So, here is my code:

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("TrayIconHide", 1)

Global Const $csAppPath = """" & @ProgramFilesDir & "\Business Objects\BusinessObjects Data Services\"

If @OSVersion = "WIN_XP" and @OSLang = "040c" Then
    
    If Not WinWait("Window file permission", "", 7200) = 0 Then
        
        While 1
            If WinWait("Window file permission", "", 5) <> 0 Then
                WinActivate("Window file permission")
                ControlClick("Window file permission", "", 2)
            Else
                ExitLoop
            EndIf
        WEnd
        
        MsgBox(0, "", "start")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "bin\DSConfig.txt"" /T /E /G BUILTIN\Utilisateurs:F /C > c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "bin\*.cfg"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "conf"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "log"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "ext"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "Admin\abap"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "DataQuality\datacleanse"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        MsgBox(0, "", "end")
        
    EndIf
    
EndIf

Obviously, the code is not working like I expected and I don't know why... Everything but the RunWait executes. When running the script, I see the START and END message box so that means that the script is going through correctly but why isn't it running my RunWait commands? Yes I know, those are DOS command lines but I wasn't able to output to a text file by using ShellExecuteWait and the cacls program since it doesn't seem to accept >> c:\uPerformRightsChanges.txt as a parameter.

So, I did some tests trying to isolate the problem. I found out that when I remove the WinWait("Window file permission", "", 5) check, the script executes the RunWait calls without any problem. So my code at that time would look like this:

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("TrayIconHide", 1)

Global Const $csAppPath = """" & @ProgramFilesDir & "\Business Objects\BusinessObjects Data Services\"

If @OSVersion = "WIN_XP" and @OSLang = "040c" Then
    
    If Not WinWait("Window file permission", "", 7200) = 0 Then
        
        While 1
            ;If WinWait("Window file permission", "", 5) <> 0 Then
                ;WinActivate("Window file permission")
                ;ControlClick("Window file permission", "", 2)
            ;Else
                ExitLoop
            ;EndIf
        WEnd
        
        MsgBox(0, "", "start")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "bin\DSConfig.txt"" /T /E /G BUILTIN\Utilisateurs:F /C > c:\uPerformRightsChanges.txt");, "", @SW_HIDE)
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "bin\*.cfg"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt");, "", @SW_HIDE)
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "conf"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt");, "", @SW_HIDE)
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "log"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt");, "", @SW_HIDE)
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "ext"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt");, "", @SW_HIDE)
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "Admin\abap"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt");, "", @SW_HIDE)
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "DataQuality\datacleanse"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt");, "", @SW_HIDE)
        MsgBox(0, "", "end")
        
    EndIf
    
EndIf

Any one knows what could be wrong here?

Thanks in advance!

Link to comment
Share on other sites

I don't understand why you made your script that way, but I'd guess what you're intending looks something like this:

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("TrayIconHide", 1)

Global Const $csAppPath = """" & @ProgramFilesDir & "\Business Objects\BusinessObjects Data Services\"

If @OSVersion = "WIN_XP" and @OSLang = "040c" Then
        
        WinWait("Window file permission", "")
        WinActivate("Window file permission")
        WinWaitActive("Window file permission")
        ControlClick("Window file permission", "", 2)
        MsgBox(0, "", "start")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "bin\DSConfig.txt"" /T /E /G BUILTIN\Utilisateurs:F /C > c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "bin\*.cfg"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "conf"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "log"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "ext"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "Admin\abap"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "DataQuality\datacleanse"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        MsgBox(0, "", "end")
        
EndIf

EDIT: Corrected script.

Edited by omikron48
Link to comment
Share on other sites

It in indeed unusual to use "If Not WinWait("Window file permission", "", 7200) = 0" - you should use it in this form: "If WinWait("Window file permission", "", 7200) <> 0 Then"

Here is what you can do:

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("TrayIconHide", 1)

Global Const $csAppPath = """" & @ProgramFilesDir & "\Business Objects\BusinessObjects Data Services\"

If @OSVersion = "WIN_XP" and @OSLang = "040c" Then
    
    If WinWait("Window file permission", "", 7200) <> 0 Then
        WinActivate("Window file permission")
        ControlClick("Window file permission", "", 2)

        MsgBox(0, "", "start")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "bin\DSConfig.txt"" /T /E /G BUILTIN\Utilisateurs:F /C > c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "bin\*.cfg"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "conf"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "log"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "ext"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "Admin\abap"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "DataQuality\datacleanse"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        MsgBox(0, "", "end")
        
    EndIf
    
EndIf

@omikron48

Your version is a little bit not accurate.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Whoops. Didn't notice that I should've taken out that timeout parameter in WinWait to replace that While loop functionality.

Correcting earlier post.

EDIT: Let me try to break down what is happening in this code block:

While 1
       If WinWait("Window file permission", "", 5) <> 0 Then
           WinActivate("Window file permission")
           ControlClick("Window file permission", "", 2)
       Else
           ExitLoop
       EndIf
WEnd

You are continuously checking whether a particular window exists then trying to activate it then doing a click on it. However, if WinWait times out (that is the window you are looking for doesn't exist within the given time frame) it will return 0 thus exiting the While loop (in essence making it so that the While loop only stops execution when the window is no longer found.

Is this code block supposed to get rid of some popup windows before you run your programs?

Edited by omikron48
Link to comment
Share on other sites

Yes that's it. This block is really needed. In this block, I'm looking for a specific window that pops up when a security problem happens and that's because the program is installed on a Windows XP computer with French OS. It never takes more than 2 hours to pop usually, to explain the first IF with the timeout set to 7200.

Now, the second IF with a timeout is there because I'm not sure how many times the security error window will pop. Also, it never pops after 5 seconds, it usually pops a certain number of times with less than 5 seconds between each one.

So now, with your advises and with more script optimization, I would get this:

AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("TrayIconHide", 1)

Global Const $csAppPath = """" & @ProgramFilesDir & "\Business Objects\BusinessObjects Data Services\"

If @OSVersion = "WIN_XP" and @OSLang = "040c" Then
    
    If WinWait("Window file permission", "", 7200) <> 0 Then
        
        While WinWait("Window file permission", "", 5) <> 0
            WinActivate("Window file permission")
            ControlClick("Window file permission", "", 2)
        WEnd
        
        MsgBox(0, "", "start")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "bin\DSConfig.txt"" /T /E /G BUILTIN\Utilisateurs:F /C > c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "bin\*.cfg"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "conf"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "log"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "ext"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "Admin\abap"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        RunWait(@ComSpec & " /c " & @SystemDir & "\cacls " & $csAppPath & "DataQuality\datacleanse"" /T /E /G BUILTIN\Utilisateurs:F /C >> c:\uPerformRightsChanges.txt")
        MsgBox(0, "", "end")
        
    EndIf
    
EndIf

That looks logical and pretty much optimized, but it don't work. The Runwait commands just don't run, I would see a certain number of command prompt windows and the output would be in a text file but nothing of this happens.

By the way, thanks for your help!

Link to comment
Share on other sites

:graduated: Hmmmm... Embarrassing...

I did not mentioned that this script is part of a Microsoft SCCM installation Package sequence I did. When executing it manually, it works fine, but when I let Microsoft SCCM 2007 run it automatically, it does not. That's when I get the problem explained up here.

I guess I'll have to figure it out myself now. :(. The problem is probably with the way Microsoft SCCM handles programs execution. Those who hate Microsoft now have another reason to bite... :D.

Seriously, if you guys have an idea of what could be wrong, let me know!

Thanks again for your help.

Link to comment
Share on other sites

Problem Fixed. Definitely nothing to do with the script.

For those it could interest, here is the explanation of what happened.

post-30968-0-66017100-1288795183_thumb.j

My AutoIt script is runned in a Batch file which is called by the SCCM installation package. SCCM runs it with its administrator account. In that Batch file, the AutoIt script is launched with the START DOS command to let me run other things at the same time and also, it allows me to end my batch file execution and still keep my AutoIt script running in the back ground. Then, the program installation runs after the batch ends. The AutoIt script keeps looking for 2 hours for security errors that may occur during the installation. If it does, well, you know what my script does. BUT here is the problem. The original Batch file which was running the AutoIt script is for sure ended at this moment and I think that batch file is like "the owner" or the "handler" for my AutoIt script, at least for the user executing it I mean. The SCCM administrator account is transfered to the AutoIt script. Inside my AutoIt script, I'm trying to RunWait and it seems like I can't do it since there is no user available to do those RunWait calls. This SCCM administrator account can only be used by SCCM itself.

I don't know if that could help and I don't know if that's clear but that's what I understand of all this situation.

Thanks. Case closed!

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...