0

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:
        try:
            shutil.copy2(sys.argv[0], filePath + 'l.exe')
        except:
            pass

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

Darren Sam
  • 35
  • 8

1 Answers1

1

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?

Community
  • 1
  • 1
Guoliang
  • 885
  • 2
  • 12
  • 20