python操作windows注册表
2012-02-28 14:48
447 查看
## file2autorun.py
import sys
import win32api
import win32con
import os
#regedit
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)
print path
print filename
#添加数据项
win32api.RegSetValueEx(hKey, filename, 0, win32con.REG_SZ, path)
win32api.RegCloseKey(hKey)
return True
def delfile2autorun(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)
print path
print filename
#删除数据项
win32api.RegSetValueEx(hKey, filename, 0, win32con.REG_SZ, "")
win32api.RegCloseKey(hKey)
return True
path = 'Foda.exe'
if addfile2autorun(path):
print "added %s to autorun" % (path,)
else:
print "fail add %s to autorun!!!" % (path, )
import sys
import win32api
import win32con
import os
#regedit
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)
print path
print filename
#添加数据项
win32api.RegSetValueEx(hKey, filename, 0, win32con.REG_SZ, path)
win32api.RegCloseKey(hKey)
return True
def delfile2autorun(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)
print path
print filename
#删除数据项
win32api.RegSetValueEx(hKey, filename, 0, win32con.REG_SZ, "")
win32api.RegCloseKey(hKey)
return True
path = 'Foda.exe'
if addfile2autorun(path):
print "added %s to autorun" % (path,)
else:
print "fail add %s to autorun!!!" % (path, )
相关文章推荐
- 操作Windows注册表的简单的Python程序制作教程
- import _winreg:用python操作修改windows注册表
- C# 操作注册表WindowsRegistry
- Python实现鼠标在屏幕随机移动操作【Windows/Linux】
- python _winreg 读取 注册表 windows error 5
- Windows驱动编程 文件读写 以及注册表操作
- 用Java操作Windows注册表
- Windows下安装Redis及使用Python操作Redis的方法
- Windows文件及注册表操作学习笔记…
- Windows内核函数(3) - 内核模式下的注册表操作
- Python3.4操作文件目录(Windows下)
- windows 平台下,运用 Python 进行简单的文件操作需要用到的函数
- java如何操作注册表(Preferences类)(在windows的注册表中保存、读取)
- Windows驱动开发(5) - 内核模式下的注册表操作
- python 操纵 控制 windows 注册表
- python在windows下实现ping操作并接收返回信息的方法
- Windows 注册表操作
- Python Windows文件操作
- Python 操作注册表
- Windows操作注册表API简单例子