`
shijunjuan
  • 浏览: 46888 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Python Registry开发

阅读更多
from _winreg import *
import traceback
import win32service
import win32serviceutil
import win32api
import win32con
import win32event
import win32evtlogutil
import os

logfile = "c:/jojo/log.txt"

def writelog(word):
	log = open(logfile,'a')
	log.write(word+"\n")
	log.close()

def updateKey(key):
	try:
		try:
			x = QueryValueEx(key, "DefaultSettings.XResolution")
			y = QueryValueEx(key, "DefaultSettings.YResolution")
			writelog("original:"+str(x[0])+":"+str(y[0]))
		except WindowsError,e:
			print('no key exists')
		SetValueEx(key,"DefaultSettings.XResolution",0,REG_DWORD,1680)
		SetValueEx(key,"DefaultSettings.YResolution",0,REG_DWORD,1050)
		x = QueryValueEx(key, "DefaultSettings.XResolution")
		y = QueryValueEx(key, "DefaultSettings.YResolution")
		writelog("change to:"+str(x[0])+":"+str(y[0]))
	except WindowsError,e:
		writelog('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
		#traceback.print_exc()

def handleKeyGroup(akey):
	for i in range(10):
		try:
			keyname = EnumKey(aKey,i)
			writelog("handling "+keyname+"\n")
			asubkey = OpenKey(aKey,keyname)
			asubkey2 = OpenKey(asubkey,"0000",0,KEY_ALL_ACCESS)
			updateKey(asubkey2)
			for j in range(10):
				try:
					subkeyname = EnumKey(asubkey2,j)
					writelog("handling "+subkeyname+"\n")
					asubkey3 = OpenKey(asubkey2,subkeyname,0,KEY_ALL_ACCESS)
					updateKey(asubkey3)
					
				except WindowsError,e:
					writelog('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
					#traceback.print_exc()	
		except WindowsError,e:
			writelog('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
			#traceback.print_exc()
		

try:
	writelog("start")
	aKey = OpenKey(HKEY_LOCAL_MACHINE, "SYSTEM\ControlSet001\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO")
	#handleKeyGroup(aKey)
	writelog("start2")
	aKey = OpenKey(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Video")
	#handleKeyGroup(aKey)
	writelog("start3")
	aKey = OpenKey(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO")
	#handleKeyGroup(aKey)
	
	
	
	
except WindowsError,e:
			writelog('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
			traceback.print_exc()

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics