Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使cx_冻结以向初创公司添加应用程序_Python_Python 3.x_Cx Freeze - Fatal编程技术网

Python 使cx_冻结以向初创公司添加应用程序

Python 使cx_冻结以向初创公司添加应用程序,python,python-3.x,cx-freeze,Python,Python 3.x,Cx Freeze,如何使cx_冻结以使创建的应用在windows启动时启动?我找不到像这样的问题的答案 就像启动时启动一样,我的意思是当计算机启动时,程序会自动启动。我还希望在首次使用该程序时自动执行此操作。您可以使用win32库创建exe的快捷方式,并将其放置在启动文件夹中 from win32com.client import Dispatch import os dir = r'C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Sta

如何使cx_冻结以使创建的应用在windows启动时启动?我找不到像这样的问题的答案


就像启动时启动一样,我的意思是当计算机启动时,程序会自动启动。我还希望在首次使用该程序时自动执行此操作。

您可以使用win32库创建exe的快捷方式,并将其放置在启动文件夹中

from win32com.client import Dispatch
import os

dir = r'C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup'
name = 'shortcut.lnk'
path = os.path.join(dir, name)
target = '<your exe>'
working_dir = '<working directory>'
icon = '<file to take the icon from, can be your exe>'

shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = working_dir
shortcut.IconLocation = icon
shortcut.save()
从win32com.client导入分派
导入操作系统
dir=r'C:\Users\\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup'
name='shortcut.lnk'
path=os.path.join(dir,name)
目标=“”
工作目录=“”
图标=“”
shell=Dispatch('WScript.shell')
快捷方式=shell.CreateShortCut(路径)
快捷方式。Targetpath=target
shortcut.WorkingDirectory=工作目录
shortcut.IconLocation=图标
shortcut.save()

希望它是自动的。什么不是自动的?希望有一个代码可以将它添加到启动中。非自动部分来自于必须手动将程序添加到启动列表中。作为最佳实践,路径应该有
r'
,或者避开反斜杠
\\
,或者使用前斜杠
/
编辑我的帖子:)