Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Code that only execute once, Python Startup folder

$
0
0

Hey and thanks for all of your answers. I try to write a piece of python code that only executes once, (first time the program is installed) and copies the program into the windows startup folders.

(C:\Users\ USER \AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup)

That's the code i wrote for this. (Please don't judge me. I know it's very shitty code. But I'm very new to coding. (this is the second little program i try to write)

import osimport shutil#get usernameuser = str(os.getlogin())user.strip()file_in = ('C:/Users/')file_in_2 = ('/Desktop/Py Sandbox/test/program.py')file_in_com = (file_in + user + file_in_2)folder_seg_1 = ('C:/Users/')folder_seg_2 = ('/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup')#create FolderPathfolder_com = (folder_seg_1 + user + folder_seg_2)shutil.copy2(file_in_com, folder_com)

Because i got an error, that there is no such internal, external, command, program or batch file named Installer. I tried to generate a batch file with nothing in it that executes when the installation process is finished.(But the error is still there.)

save_path = 'C:/Windows/assembly/temp'name_of_file = str("Installer")completeName = os.path.join(save_path, name_of_file+".bat")file1 = open(completeName, "w")file1.close()

The main idea behind this that there is my main Program, you execute it it runs the code above and copies itself to the startup folder. Then the code the whole installer file gets deleted form my main program.

import Installer#run Installer Fileos.system('Installer')os.remove('Installer.py')

But maybe there's someone out there who knows the answer to this problem. And as I said earlier, thanks for all of your answers <3.

BTW I'm currently using Python 3.5.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>