I am trying to call an executable at startup, which will call another executable itself. For the first part, I simply added the path to the executable to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run, which works, my executable is called at startup.
The latter contains, among others, these lines :
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
proc = subprocess.Popen(command, startupinfo=startupinfo)
However, a command shell (cmd) pops when the computer starts. Everything works fine, but it is visible instead of hidden… So basically, how do I hide this command shell ?
When using ProcessExplorer, I have the following hierarchy :
+ System
|_ Interrupts
|_ smss.exe
|_ some processes...
+ explorer.exe
|_ some processes...
|_ MYSCRIPT.EXE
Here is the sequence I try to achieve :
- I create an ISO file containing all the Python executable I want to run on the VM. One of them (
master.exe) calls the others. - I create a VM which automatically mount the latter
- The VM, which was prepared, has a scheduled task which calls
D:\master.exe master.exe(among other tasks which are not our concern here) adds the valueD:\myscript.exetoHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run- The VM reboots
D:\myscript.exeis run (and it works fine and as attended), but it does run in a command prompt, which I would like to be invisible.
This is a typical problem Python-programmers encounter – and therefore, a solution is offered by Python itself. It has been asked on SO many times, e.g., here, but for you, the problem is a little more complicated.
It’s all about whether you use
python.exeorpythonw.exeto run your script. For the first one, a console is opened, for the second it’s not.As you use compiled scripts, you have to tell “the compiler” which version you want to use. Assuming you are using py2exe, you can have a look at this post on SO. Here it is explained in detail how to proceed.