Sign in to follow this  
Followers 0
Vadersapien

Close app when icon is clicked

10 posts in this topic

Hello all,

I would like to know if and how I can close my AutoIt app when it's icon is clicked (instead of opening another one).


Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.

Share this post


Link to post
Share on other sites



Do you mean make it so your script can only have one instance of it open at a time?

If so, look into the _Singleton command.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

No I want it to work like this:

You click the icon --> Application opens

You click the icon again(While the app is still open) --> Application closes

Edited by Vadersapien

Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.

Share this post


Link to post
Share on other sites

If you try Mison's suggestion it may not work because you might now have a window. However, you could use the same idea he suggested with using ProcessExists and ProcessClose instead of the Win* commands he had.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

If you try Mison's suggestion it may not work

Yeah I tried that myself...it was the first thing I thought of...and it didn't work...

I'll have a go at ProcessExists and ProcessClose...but would this work with multiple instances of the application.


Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.

Share this post


Link to post
Share on other sites

If you try Mison's suggestion it may not work because you might now have a window. However, you could use the same idea he suggested with using ProcessExists and ProcessClose instead of the Win* commands he had.

I thought about that too, but I don't have enough experience in working with ProcessExists and ProcessClose.

I use the script I had posted to check if my application(with GUI) is already running, and will wxit if that is true.


Hi ;)

Share this post


Link to post
Share on other sites

oh and by the way, you'll have to compile it first before you can test it because Scite won't allow you to run the same script if it's already running.. but I'm sure you all already know that :)


Hi ;)

Share this post


Link to post
Share on other sites

Yeah I tried that myself...it was the first thing I thought of...and it didn't work...

I'll have a go at ProcessExists and ProcessClose...but would this work with multiple instances of the application.

I don't think it would work with multiple instances. Processes started from the same .exe file have the same process name from what I remember. Each process has it's own individual PID number; but I'm not sure how that would help.

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

So like this? (Must be a compiled script, won't work in SciTE for obvious reasons)

_CloseProcess (@ScriptName)

While 1
    Sleep (100)
WEnd

Func _CloseProcess($varProcess)
    $varClosedProcess = 0
    $PList = ProcessList()
    For $x = 1 to $PList[0][0]
        If StringInStr ($PList[$x][0], $varProcess) Then
            If $PList[$x][1] <> @AutoItPID Then
                $varClosedProcess = 1
                ProcessClose ($PList[$x][1])
                Sleep (100)
            EndIf
        EndIf
    Next
    If $varClosedProcess = 1 Then Exit
EndFunc
Edited by exodius

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