[SOLVED] Calling the main function after running explorer (python)


I wrote a app that restarts explorer.exe but the problem is that after i re-open explorer.exe it should call the main function again, but it doesn’t.
The ‘funny’ stuff that i found is that if i dont open explorer.exe, the main function will be called as it should.

import os
def sendCmd(command):
    return os.system(command)

# Main function
def Main():
    q = input() # Checks for input
    if q == "1": # If the option 1 is selected
        sendCmd("taskkill /f /im explorer.exe") # Kills explorer
        sendCmd("explorer.exe") # Opens explorer



nice question, my guess is that python uses the main thread when explorer.exe is open so it is not going forward to the Main() function and does not do that command. try to close explorer.exe manually and check if the program calls the main function.

Anyway, To solve that you can call the sendCmd("explorer.exe") in another thread and your program will continue to the Main() line (I would use while True in this case instead of recursion https://www.geeksforgeeks.org/difference-between-recursion-and-iteration/)

th = threading.Thread(target=sendCmd, args=('explorer.exe', ))
# Start the thread

Answered By – רן מורסקי

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *