Jump to content
Sign in to follow this  
tinkythomas

Script runs fine until compiled!

Recommended Posts

tinkythomas

Hi,

This has been driving me nuts for hours now and I just can't see what is wrong? The script runs fine until it's compiled then it won't run as expected.

The first problem is that if the process exists then the function Kill_Process is called to kill the required processes. Then the second function to launch a program is called. This works as expected when executed from scite, but only the first function runs when compiled).

The second problem is if I manually kill off the processes then run the script only the second function should run. This works as expected from scite, but not when compiled. It gets as far as launching the program but gets stuck at the admin - login screen right where username and password is entered.

If anybody can see what's wrong if anything with my code, I would be grateful.

Opt("MustDeclareVars", 1)
Opt("TrayIconDebug", 1)

Global $proc1, $proc2, $proc3
Global $Processes
Global $name
Global $prEx
Global $prcls
Global $lnk
Global $handle

$proc1 = "Tachomaster.exe"
$proc2 = "postgres.exe"
$proc3 = "postmaster.exe"

$lnk = @DesktopCommonDir & "\Tachomaster.lnk"
$prEx = ProcessExists($proc3)

If Not $prEx = 0 Then
    Call("Kill_Process")
    Call("Launch_Tacho")
Else
    Call("Launch_Tacho")
EndIf

Func Kill_Process()
    $Processes = ProcessList()
    For $i = 1 To $Processes[0][0]
        $name = $Processes[$i][0]
        Switch $name
            Case $proc1
                ProcessClose($proc1)
            Case $proc3
                ProcessClose($proc3)
        EndSwitch
    Next
EndFunc   ;==>Kill_Process

Func Launch_Tacho()
    Opt("WinTitleMatchMode", 1)
    Opt("WinWaitDelay", 1000)
    Opt("SendKeyDelay", 30)
    ProcessWaitClose($proc2)
    Run(@ComSpec & ' /c "' & $lnk & '"', '', @SW_HIDE)
    WinWait("Admin - Login", "")
    If Not WinActive("Admin - Login", "") Then
        WinActivate("Admin - Login", "")
    EndIf
    WinWaitActive("Admin - Login", "")
    Send("********{TAB}********{ENTER}")
    WinWait("Tachomaster", "Help")
    If Not WinActive("Tachomaster", "Help") Then
        WinActivate("Tachomaster", "Help")
    EndIf
    WinWaitActive("Tachomaster", "Help")
    $handle = ControlGetHandle("Tachomaster", "Chart Scanner", "Chart Scanner")
    ControlClick("Tachomaster", "Chart Scanner", $handle)
EndFunc   ;==>Launch_Tacho

Exit

Thank-you

Share this post


Link to post
Share on other sites
tinkythomas

Hi,

I have now solved this although I don't have a clue what was wrong? I simply copied the code from the old script into a new script, compiled and it now works!!!

Oh well, I have wasted some much time on this, but I suppose it's just one of those things that makes no sense, well not to me anyway :)

Share this post


Link to post
Share on other sites
tinkythomas

Right I inadvertantly discovered the problem. After I had copied the original script to the new, I had given it a new file name. I then preceded to change the new file name back to the original after it had been deleted.

Then when I tried to execute again, it wouldn't run :lmao: I then discovered that I had named the script file the same as the target file :)

So after changing the file name all was working again.

Sorry to have wasted anybody's time, but I thought that I should share this with you.

Thanks

Edited by tinkythomas

Share this post


Link to post
Share on other sites
Inverted

You should make a blog about this experience :)

Share this post


Link to post
Share on other sites
wolf9228

Hi,

This has been driving me nuts for hours now and I just can't see what is wrong? The script runs fine until it's compiled then it won't run as expected.

The first problem is that if the process exists then the function Kill_Process is called to kill the required processes. Then the second function to launch a program is called. This works as expected when executed from scite, but only the first function runs when compiled).

The second problem is if I manually kill off the processes then run the script only the second function should run. This works as expected from scite, but not when compiled. It gets as far as launching the program but gets stuck at the admin - login screen right where username and password is entered.

If anybody can see what's wrong if anything with my code, I would be grateful.

Opt("MustDeclareVars", 1)
Opt("TrayIconDebug", 1)

Global $proc1, $proc2, $proc3
Global $Processes
Global $name
Global $prEx
Global $prcls
Global $lnk
Global $handle

$proc1 = "Tachomaster.exe"
$proc2 = "postgres.exe"
$proc3 = "postmaster.exe"

$lnk = @DesktopCommonDir & "\Tachomaster.lnk"
$prEx = ProcessExists($proc3)

If Not $prEx = 0 Then
    Call("Kill_Process")
    Call("Launch_Tacho")
Else
    Call("Launch_Tacho")
EndIf

Func Kill_Process()
    $Processes = ProcessList()
    For $i = 1 To $Processes[0][0]
        $name = $Processes[$i][0]
        Switch $name
            Case $proc1
                ProcessClose($proc1)
            Case $proc3
                ProcessClose($proc3)
        EndSwitch
    Next
EndFunc   ;==>Kill_Process

Func Launch_Tacho()
    Opt("WinTitleMatchMode", 1)
    Opt("WinWaitDelay", 1000)
    Opt("SendKeyDelay", 30)
    ProcessWaitClose($proc2)
    Run(@ComSpec & ' /c "' & $lnk & '"', '', @SW_HIDE)
    WinWait("Admin - Login", "")
    If Not WinActive("Admin - Login", "") Then
        WinActivate("Admin - Login", "")
    EndIf
    WinWaitActive("Admin - Login", "")
    Send("********{TAB}********{ENTER}")
    WinWait("Tachomaster", "Help")
    If Not WinActive("Tachomaster", "Help") Then
        WinActivate("Tachomaster", "Help")
    EndIf
    WinWaitActive("Tachomaster", "Help")
    $handle = ControlGetHandle("Tachomaster", "Chart Scanner", "Chart Scanner")
    ControlClick("Tachomaster", "Chart Scanner", $handle)
EndFunc   ;==>Launch_Tacho

Exit

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
tinkythomas

Right I inadvertantly discovered the problem. After I had copied the original script to the new, I had given it a new file name. I then preceded to change the new file name back to the original after it had been deleted.

Then when I tried to execute again, it wouldn't run :lmao: I then discovered that I had named the script file the same as the target file :)

So after changing the file name all was working again.

Sorry to have wasted anybody's time, but I thought that I should share this with you.

Thanks

Further to my earlier post, I have discovered that the application launched by my script, kills any instances that are open at startup.

The application looks for any process by the name of Tachomaster.exe. Because the compiled script name was the same as the application name, this was the reason it was being terminated. This is why the non-compiled script was working without problem, just took me a while to figure that out.

Regards

Share this post


Link to post
Share on other sites
tinkythomas

Thanks wolf9228 for the revised code. Is it preferable to use the WMI service when terminating processes, instead of the native Autoit functions? I tried this code and it works very nicely, so thank-you for that.

Regards

Share this post


Link to post
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
Sign in to follow this  

×