Sign in to follow this  
Followers 0
trwagner1

Force Process Close Problem

9 posts in this topic

I'm working on an automated enterprise program installation that includes multiple application installs.

During one of the individual installations, the application launches a process that is sent to the system tray. Let's call it "something.exe"

It cannot be accessed through a window, it's just a tray program that is running. And, there's no hot-key to activate the application.

But, in order for the installation to continue, I have to terminate that exe.

Here are two code snippets of what I've been trying:

$Process = "something.exe"
while 1

    If ProcessExists($Process) Then
        ProcessClose($Process, 2)
        Sleep(5000)
    EndIf
WEnd
MsgBox(0,"",$Process & " Terminated",0)
Exit

And

$Process = "something.exe"

while 1
    If ProcessExists($Process) Then
       Do
            ProcessClose($Process, 2)
       Until Not ProcessExists($Process)
       EndIf
WEnd

MsgBox(0,"",$Process & " Terminated",0)

Exit

In both cases, the compiled AutoIt exe runs then pauses. It never closes the process and the application never ends itself.

I've also just tried simply:

$Process = "something.exe"
ProcessClose($process)

and

$Process = "something.exe"
ProcessWaitClose($process)

With similar results.

Additionally, I'm using the local admin to perform all the steps within the script. I use the RunAsWait() as one of the first functions in the script.

From what I'm reading,

ProcessClose($Process, 2)
should forcefully close the process. But, it's not. Is there an altnerate method?

Thanks

Ted

Share this post


Link to post
Share on other sites



If you could give some insight to the application, we may be able to help automate closing it; but if it's a protected process like a virus scanner, this is not the right forum.

Share this post


Link to post
Share on other sites

If you could give some insight to the application, we may be able to help automate closing it; but if it's a protected process like a virus scanner, this is not the right forum.

The application is a proprietary application. QA Director from Compuware.

The application itself is a little exe that's called a "test execution server". I can right click on it and select exit as any logged in user (admin or otherwise).

Is there a way to use AutoIt to block a process from executing?

Ted

Share this post


Link to post
Share on other sites

There are tray management functions that let you interact with the tray icons and menus. I believe they are UDFs and you can find them by trying different search terms. Try searching for something like "+system +tray +menu".

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

From what I'm reading,

ProcessClose($Process, 2)
should forcefully close the process. But, it's not. Is there an altnerate method?
I wonder, did you read this part:

ProcessClose

Parameters

process The title or PID of the process to terminate.

flag [optional] if different from zero will force closing of handles to child stream if any defined in the Run() execution. process must be defined as a PID.

So if you have

$Process = "something.exe"

then it should be

ProcessClose(ProcessExists($Process), 1)

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Siao,

Yes, I tried that as well. Sorry did not include that in the original post.

But, that did not work as well.

Ted

I wonder, did you read this part:

So if you have

$Process = "something.exe"

then it should be

ProcessClose(ProcessExists($Process), 1)

Share this post


Link to post
Share on other sites

Thanks Richard, I will do some digging and experimenting with that.

If I figure it out, I will post my solution.

Ted

There are tray management functions that let you interact with the tray icons and menus. I believe they are UDFs and you can find them by trying different search terms. Try searching for something like "+system +tray +menu".

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Wow, this worked great.

Because the process didn't close 100% of the time using ProcessClose() I followed Richard's suggestion and found the discussion related to SysTray_UDF.

So, here's how I closed that exe (generic code follows. replace something.exe with your tray app executable name)

#include <SysTray_UDF.au3>

clickfunc()

Func clickfunc()
    $index = _SysTrayIconIndex("something.exe", 0)
    $pos = _SysTrayIconPos($index)

    MouseClick("Right", $pos[0], $pos[1], 2)
    Send("x")
EndFunc ;==>clickfunc
Exit

Many thanks to the SysTray_UDF reference. I got the solution from the large taupe thread.

SysTray_UDF Thread

Note: If you use the code above, you can't use the systray_udf file found in the general install! You have to use the one found here: NEW SysTray_UDF.au3

Edited by trwagner1

Share this post


Link to post
Share on other sites

Glad to help. As soon as I read that it could be closed by user interactive means, it just made sense to close it that way.

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  
Followers 0