Skip to content

Instantly share code, notes, and snippets.

@smallsong
Created August 15, 2019 15:18
Show Gist options
  • Save smallsong/d830c768fe0b7ee8581931c754387349 to your computer and use it in GitHub Desktop.
Save smallsong/d830c768fe0b7ee8581931c754387349 to your computer and use it in GitHub Desktop.
python打包后exe开机自动启动
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import win32api
import win32con
class AutoRun():
def __init__(self):
name = 'translate' # 要添加的项值名称
path = 'D:\\python_work\\work\dist\\translate.exe' # 要添加的exe路径
# 注册表项名
KeyName = 'Software\\Microsoft\\Windows\\CurrentVersion\\Run'
# 异常处理
try:
key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, KeyName, 0, win32con.KEY_ALL_ACCESS)
win32api.RegSetValueEx(key, name, 0, win32con.REG_SZ, path)
win32api.RegCloseKey(key)
except:
print('添加失败')
print('添加成功!')
if __name__=='__main__':
# auto=AutoRun();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment