I need to run a program (a python script made into an exe) on start up, without the console showing up. In some question, I found the solution, i.e to execute the program. Right now, I'm testing it out with a simple python program filewriter.py that does -
while count != 1000:
f = open('test.txt','a+')
f.write(str(count))
f.close()
sleep 1
The bat file tool.bat :
@ECHO OFF
python "<absolute_path_here>\filewriter.py"
EXIT /B
The VBS file :
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "<absolute_path_here>\tool.bat" & Chr(34), 0
Set WinScriptHost = Nothing
If I execute the VBS file (double-click it), everything works fine. The output file appears, without the console appearing. So I added it to registry under
HKCU\Software\Microsoft\CurrenVersion\Run
as WScript "path_to_the_vbs_file".
On Startup, the VBS file executes properly (verified it by adding a MsgBox which displayed the popup) but the call to the bat file is not being executed. How do I make this work?
In windows there are two python executables: python.exe
, pythonw.exe
. If you don't wish to see the terminal window you must use pythonw.exe
.
I need to run a program (a python script made into an exe).
If you covert your script to .exe
with help of py2exe
it is simillar. You can assing your script to console
or windows
. Look to Py2exe Tutorial, the console
variable can be replace forwindows
.
You don't need to create EXE files from python. You can run pythonw.exe
with path as argument to your script. Why do you need to create .bat
which you run from vbscript
? Look here: Run on windows startup CMD with arguments
I forgot to say, that the Windows Python installer normally create following file association, so the script can run directly.
python.exe
pythonw.exe
Other way how you can run the the script on boot is to use Windows Scheduler. The big advantage is you can setup user rights or more events when start the script. You can run the script manually too and you will last status.
Create Python .exe
is sometimes tricky. If you don't need to distribute your script to multiple computers I prefer don't use.