# 开始时,直接使用secedit(Audit策略)配置文件时,总是无法
# 进行比对成功,无论使用find函数还是使用正则匹配。
# 后来发现将导出的文件换成其他的文件可以实现目标。
# 与“昵称已改”网友的交流中,想到自己应该是出错在文件类型。
# 对于文件类型的处理则花费了自己两天的时间。
# open()函数中直接使用(u' ','r')不可以,
# 导入import codecs也不可以。后来发现使用secedit命令,注册表的导出
# 命令————regedit /e 同样会使得导出的文件的编码格式为@@@Unicode@@@@
#
# 尝试各种方法进行更改该格式。最后使用DOS命令type就可以了,有网友给出
# 增强版的typex命令。
# 使用导出的函数时,可以使用type命令来更改文件的
import sys,os
import re
import codecs
def seceditCheck():
retuRe=os.system("secedit /export /cfg exportSetting.inf")
#the encoding of exportSetting.inf file is Unicode
#Translate it into ANSCI
os.system("type exportSetting.inf>exportCurSetting.inf")
#look2 = codecs.lookup( " utf-8 " )
if retuRe==740:
print("请使用本地管理员身份运行")
else:
patten=['MinimumPasswordLength','PasswordComplexity','PasswordHistorySize',
'MaximumPasswordAge','EnableGuestAccount',]
seceditResult=[]
with open('exportCurSetting.inf','r') as data:
for line in data:
for itemsP in patten:
if re.search(itemsP,line):
seceditResult.append(line)
break
else:
string=(("nothing"))
return seceditResult
r=seceditCheck()
print(r)