1

I'm making a minecraft console client script for a friend It opens the console client based on a txt file

I figured out how to kill/terminate the window but this part doesn't physically close the window it just sets it to a normal command prompt window because it's created using a batch command

How would I close a program completely by name as if I pressed the "x" button in the top right hand corner of the application.

    os.system("taskkill /f /im MinecraftClient.exe")
 //for proc in psutil.process_iter():
   //  if proc.name() == "MinecraftClient.exe":
   //      proc.terminate()
   //      reap_children()

Neither of those actually closes the .exe it just changes it into a command prompt window. And I don't want to have to run through the for proc in psutil.process_iter() again just to close the command prompt windows.

EDIT 1:

How it opens the MinecraftClient.exe please keep in mind it is a console client that you download from github

def connect(file, directory, executeds):
with open(file) as file:
    for line in file:
        #stdout=PIPE, stderr=PIPE, stdin=PIPE,
        lines = line.split(":")
        login = lines[0]
        password = lines[1]
        IP = lines[2]
    //     CREATE_NEW_PROCESS_GROUP = 0x00000200
   //      DETACHED_PROCESS = 0x00000008
        command = "MinecraftClient.exe {0} {1} {2}".format(login, password, IP)
        executed = Popen("start cmd /K " + command, cwd=directory, shell=True)
        out, err = executed.communicate()
        executeds.append(executed.pid)
        if executed.returncode == 0:
            print("Connected {0} to {1} successfully".format(login, IP))
        else:
            print("Failed to connect {0} to {1}.".format(login, IP))
            print("{0}".format(err))

        time.sleep(3)

Some things I'm not using because they were just tests

1 Answers1

4

I just checked, and I can't find anything called MinecraftClient.exe running for me. The Minecraft process is actually called javaw.exe - try killing that instead. If this is not the problem, I managed it with the subprocess module as such:

import subprocess
subprocess.call("taskkill /f /im javaw.exe", shell=True)

shell=True prevents it from opening a command prompt on your screen.

EDIT
Your screenshots show that it ends up becoming cmd.exe - try killing that instead?
Okay, after downloading the program I managed to successfully kill it using subprocess.call('taskkill /f /im MinecraftClient.exe & taskkill /f /im cmd.exe', shell=True)

Community
  • 1
  • 1
Code Enjoyer
  • 681
  • 4
  • 18
  • MinecraftClient.exe is a downloaded app that is used to AFK farms on minecraft. I use a batch command starting it with cmd to open the .exe but when I close it it changes it to a regular old command prompt window so I don't want to have to add another os.system or for proc in psutil.process_iter() just to close the command prompt window also. I'll make an edit to show the connect function – RevealYourPuss Apr 01 '18 at 05:31
  • the console client isn't handled by minecraft itself it's its own application that uses minecraft services to connect to minecraft servers. Just google minecraft console client it'll be the first github link – RevealYourPuss Apr 01 '18 at 05:37
  • Forgot to mention the way you suggested it just changes it to a command prompt window as well. This is what it's like after calling the close function https://gyazo.com/ebbef76853328eef3c130cbb3da27e26 This is what it's like before calling the close function https://gyazo.com/16eb61bbc8c84190c92d75ee7769a930 The very end of the image isn't supposed to be there because I just got kicked because I was on a VPN when logging in. But if I wasn't on a VPN it'll be like I was on the server but can't move. – RevealYourPuss Apr 01 '18 at 06:45
  • Okay I wanted to avoid ending cmd itself but I guess I'll have to do it. – RevealYourPuss Apr 01 '18 at 18:21