分享

一键开机启动添加(python)

 liluvu 2012-10-23

一键开机启动添加(python)

添加文件到run注册表里面去

## file2autorun.py
import sys
import win32api
import win32con
import os
def addfile2autorun(path):
     runpath = "Software\Microsoft\Windows\CurrentVersion\Run"
     hKey = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, runpath, 0, win32con.KEY_SET_VALUE)
     path = os.path.abspath(path)
     if False == os.path.isfile(path):
         return False
     (filepath, filename) = os.path.split(path)
     win32api.RegSetValueEx(hKey, filename, 0, win32con.REG_SZ, path)
     win32api.RegCloseKey(hKey)
     return True
if len(sys.argv) == 1:
     print "usage: file2autorun.py %filepath%"
else:
     path = sys.argv[1];
     if addfile2autorun(path):
         print "added %s to autorun" % (path,)
     else:
         print "fail add %s to autorun!!!" % (path, )

右键菜单添加懒得写了,人肉改注册表:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Python.File\shell\Add2AutoRun]

[HKEY_CLASSES_ROOT\Python.File\shell\Add2AutoRun\command]
@="python \"e:\\python\\file2autorun.py\" \"%1\""

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多