0

I have a Python program which I compiled into a .exe file using PyInstaller. When you open the .exe, there should be no console, no command prompt or whatever. It should run the Python program in the background completely silently.

Is it possible to put something in the Python script so that it does not open a command prompt and executes silently?

3 Answers 3

1

Save this one line of text as file invisible.vbs:

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

To run any program or batch file invisibly, use it like this:

wscript.exe "C:\Wherever\invisible.vbs" "C:\Some Other Place\MyBatchFile.bat"

To also be able to pass-on/relay a list of arguments use only two double quotes

CreateObject("Wscript.Shell").Run "" & WScript.Arguments(0) & "", 0, False

Example: Invisible.vbs "Kill.vbs ME.exe"

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer, but I want to use my exe file for this. Is it still possible?
Sorry I misread what you needed, try the following: Save this one line of text as file invisible.vbs: CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False To run any program or batch file invisibly, use it like this: wscript.exe "C:\Wherever\invisible.vbs" "C:\Some Other Place\MyBatchFile.bat" To also be able to pass-on/relay a list of arguments use only two double quotes CreateObject("Wscript.Shell").Run "" & WScript.Arguments(0) & "", 0, False Example: Invisible.vbs "Kill.vbs ME.exe" I'll replace this as an answer.
1

You can use the --noconsole option, if this doesn't work change the spec file setting "console" to False.

Comments

1

Yes, on windows you can create a bat-file like this:

start /B your_file.exe

add this code to your app:

import ctypes
import os
import win32process

hwnd = ctypes.windll.kernel32.GetConsoleWindow()      

    if hwnd != 0:      
        ctypes.windll.user32.ShowWindow(hwnd, 0)      
        ctypes.windll.kernel32.CloseHandle(hwnd)
        _, pid = win32process.GetWindowThreadProcessId(hwnd)
        os.system('taskkill /PID ' + str(pid) + ' /f')

5 Comments

Is it start /B or start /b? I used start /b before but will it do/is it the same as start /B?
I created a .bat file with start /B myfile.exe and I double clicked the .bat file, but it still opens a command prompt. I want it to be completely in the background. Is this possible?
I use this method and works (not opening the cmd console), now you have to tell your python not to show its CLI.
How do I do this?
Updated answer. From this: stackoverflow.com/questions/1689015/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.