Vadersapien Posted November 5, 2009 Share Posted November 5, 2009 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. Link to comment Share on other sites More sharing options...
exodius Posted November 5, 2009 Share Posted November 5, 2009 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. Link to comment Share on other sites More sharing options...
Vadersapien Posted November 5, 2009 Author Share Posted November 5, 2009 (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 November 5, 2009 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. Link to comment Share on other sites More sharing options...
Mison Posted November 5, 2009 Share Posted November 5, 2009 #include <guiconstants.au3> If WinExists("Test 1000") Then WinClose("Test 1000") Exit EndIf GUICreate("Test 1000") GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit Sleep(10) WEnd Hi ;) Link to comment Share on other sites More sharing options...
Achilles Posted November 5, 2009 Share Posted November 5, 2009 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] Link to comment Share on other sites More sharing options...
Vadersapien Posted November 5, 2009 Author Share Posted November 5, 2009 If you try Mison's suggestion it may not workYeah 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. Link to comment Share on other sites More sharing options...
Mison Posted November 5, 2009 Share Posted November 5, 2009 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 ;) Link to comment Share on other sites More sharing options...
Mison Posted November 5, 2009 Share Posted November 5, 2009 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 ;) Link to comment Share on other sites More sharing options...
Achilles Posted November 5, 2009 Share Posted November 5, 2009 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] Link to comment Share on other sites More sharing options...
exodius Posted November 5, 2009 Share Posted November 5, 2009 (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 November 5, 2009 by exodius Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now