Darren Sam Darren Sam - 2 years ago 93
Python Question

adding file to start up of windows 8.1 uisng python 2.7

I have a following code which adds a particular file to startup of windows

userName = getpass.getuser()
filePath = 'C:\Users\%s\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup' %userName

if os.path.exists(filePath):
if os.path.isfile(filePath + 'l.exe') == False:
shutil.copy2(sys.argv[0], filePath + 'l.exe')

but this is not adding the file to start up ..
I dont understand why ..
can anyone plz help me..

Answer Source

if userName is abc, filePath will be C:\Users\abc\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup, filePath + 'l.exe' will be C:\Users\abc\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startupl.exe -- you should find the issue now, right?

I would sugguest to use os.path.join(filePath, 'l.exe') and don't just pass an exeception, at least you want to print out the exception to get the details. How to print an error in Python?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download