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()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值