Sign in to follow this  
Followers 0
Dinosaurr

Closing a certain program

4 posts in this topic

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)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is really basic

While 1
    ProcessClose("Game1.exe")
    ProcessClose("Game.exe")
    ProcessClose("DATOS.exe")
    Sleep(10)   ;for CPU idle
WEnd
P.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 by Varian

Share this post


Link to post
Share on other sites

This is really basic

While 1
    ProcessClose("Game1.exe")
    ProcessClose("Game.exe")
    ProcessClose("DATOS.exe")
    Sleep(10)   ;for CPU idle
WEnd
P.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)

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Varian

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