Dinosaurr Posted January 28, 2011 Share Posted January 28, 2011 I'm sorry I could not come up with a more creative title. My situation: I am trying to create a simple program that will close a game as it opens on my computer. I know there are other software with this purpose, but that is not the point. As of now, this is the code I have. #NoTrayIcon $Game1 = "Game1.exe" $Game = "Game.exe" $DATOS = "DATOS.exe" While 1 EndGame() WEnd Func EndGame() WinKill("Game") If ProcessExists($Game1) Then ProcessClose($Game1) EndIf If ProcessExists($Game) Then ProcessClose($Game) EndIf If ProcessExists($DATOS) Then ProcessClose($DATOS) EndIf Sleep(20000) EndFunc Game1, Game, and DATOS are process names for possible process the game might be under (more about this in a bit) Wintitle Game is because it appeared to me that they could change the name of the executable that is running and change the process name, but it also occurred to me that if the person was intelligent enough they could find ways to also change the window title. Realizing my own script is very rudimentary and probably not very efficient I ask, What methods would you recommend to accomplish this task? Or is my search a futile one. Thank you for taking the time to read my post. (By the way, this is not a virus. Just a project I decided to undertake) Link to comment Share on other sites More sharing options...
Varian Posted January 28, 2011 Share Posted January 28, 2011 (edited) This is really basicWhile 1 ProcessClose("Game1.exe") ProcessClose("Game.exe") ProcessClose("DATOS.exe") Sleep(10) ;for CPU idle WEndP.S. Thanks for asking so politely!! EDIT: I did not put it in the script, but it's always a good idea to add a Hotkey for exiting the script when using endless loops (at least while you are testing them) Edited January 28, 2011 by Varian Link to comment Share on other sites More sharing options...
Dinosaurr Posted January 28, 2011 Author Share Posted January 28, 2011 This is really basicWhile 1 ProcessClose("Game1.exe") ProcessClose("Game.exe") ProcessClose("DATOS.exe") Sleep(10) ;for CPU idle WEndP.S. Thanks for asking so politely!! EDIT: I did not put it in the script, but it's always a good idea to add a Hotkey for exiting the script when using endless loops (at least while you are testing them) Thank you for your post, but I think you misunderstood. Yes, the method of closing by process name works, until they change the name of the executable which in turn changes the name of the process. Which can be remedied somewhat by closing by window title, but this also can be changed. So I am asking if there is a more effective way other than the ones I am using currently. (yeah the hotkey's are a good idea when testing, but I just comment out #NoTaskIcon when testing) Link to comment Share on other sites More sharing options...
Varian Posted January 28, 2011 Share Posted January 28, 2011 (edited) You will then need to discover what it process that it could be by process of elimination. Firstly, I'll assume that the Window is always going to be visible. So I would try to find a unique control or get the list of classes with WinGetClassList() to improve the accuracy of the script since you may not know the Process name or the Window Title.While 1 $Array = WinList() If Not IsArray($Array) Then ;there will always be a Window if the OS is running, but put here anyway Sleep(10) ;for CPU idle ContinueLoop EndIf For $i = 1 To $Array[0][0] If Not BitAND(WinGetState($Array[$i][1]), 2) Then ContinueLoop ;if window is not visible, then go to next element Local $wClass = "" ;identify the Class of the Game Window with Au3Info Tool Local $wTitle = "[TITLE:" & $Array[$i][1] & "; CLASS:" & $wClass & "]" ;=============================================================================== $sControl = "" ;Try to find as unique a Control that will only be present in the Game Window with the Window Class If ControlCommand($wTitle, "", $sControl, "IsVisible", "") Then ProcessClose($Array[$i][1]) ContinueLoop EndIf ;=============================================================================== ;alternatively, you can get the classes from the game window and compare enough of them to make the game window unique ;or you can do both to further qualify the window $Class_List = WinGetClassList($Array[$i][1]) If ControlCommand($wTitle, "", $sControl, "IsVisible", "") Then If StringInStr($Class_List, "Edit") And StringInStr($Class_List, "msctls_Statusbar32") Then ProcessClose($Array[$i][1]) ContinueLoop EndIf EndIf ;=============================================================================== Next Sleep(10) ;for CPU idle WEnd Edited January 28, 2011 by Varian 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