python Packaging exe Boot Auto Startup Instance of windows
- 2021-07-03 00:39:34
- OfStack
1. Background
Simply write a. exe program, there is no need to learn mfc, c + +, etc., you can learn python. python can easily call windows api, easy to achieve what you want to do. The following is to realize the automatic startup of the packaged exe file.
2. Implement
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import win32api
import win32con
class AutoRun():
def __init__(self):
name = 'translate' # Name of the item value to add
path = 'D:\\python_work\\work\dist\\translate.exe' # To add exe Path
# Registry key name
KeyName = 'Software\\Microsoft\\Windows\\CurrentVersion\\Run'
# Exception handling
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(' Add failed ')
print(' Add successfully! ')
if __name__=='__main__':
# auto=AutoRun();