我想让我的脚本在启动时自动运行,然后通过pyinstaller工具将其转换为EXE,
*点击速度.EXE“程序名”,它将自己复制到计算机上的特定路径,然后在启动文件夹中生成一个bat文件“它包含启动代码”SPPED.EXE文件'
但我的问题是bat文件不能在start上运行*import os
import ftplib
import sys
import shutil
import getpass
##################copy script into startup#######################
def copy_script():
USER_NAME = getpass.getuser()
src=sys.argv[0]
dst = r'C:\Users\%s\AppData' % USER_NAME
shutil.copy2(src,dst)
dst='C:\Users\\"%s"\AppData\SPEED.exe' % USER_NAME ######name of script after making EXE
add_to_startup(USER_NAME,file_path=dst)
return None
######################################make a bat file to run on startup######
def add_to_startup(USER_NAME,file_path):
if file_path == "":
file_path = os.path.dirname(os.path.realpath(__file__))
bat_path = r'C:\Users\%s\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup' % USER_NAME
with open(bat_path + '\\' + "open.bat", "w") as bat_file:
bat_file.write(r'@echo off'+ os.linesep) ## to hide console batch file when it run
bat_file.write(r'start "" %s' % file_path)
if __name__=='__main__':
copy_script()
start() ##it is function that i make it