opus-nt/scripts/api/registry.py

53 lines
1.4 KiB
Python
Raw Normal View History

2019-12-26 06:20:41 +00:00
global subprocess
import subprocess
global winreg
import winreg
opus.reg = Munch()
opus.reg.sep = "\\"
opus.reg.path = "OPUS_TMP"
def _regUnmount():
opus.main.output("registry > unmount",2)
rtn = subprocess.call(["reg","unload","HKLM" + opus.reg.sep + opus.reg.path])
if rtn > 0: raise Exception("reg")
opus.reg.unmount = _regUnmount
def _regMount(i):
try:
opus.reg.unmount()
except:
opus.main.output("unmount failed, probably already unmounted",2)
opus.main.output("registry > mount > " +i,2)
rtn = subprocess.call(["reg","load","HKLM" + opus.reg.sep + opus.reg.path,i])
if rtn > 0: raise Exception("reg")
opus.reg.mount = _regMount
def _regImport(rp):
opus.main.output("registry > import > " +rp,2)
rtn = subprocess.call(["reg","import",rp])
if rtn > 0: raise Exception("reg")
opus.reg.imprt = _regImport
def _getValue(kp,v):
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,kp) as key:
return winreg.QueryValueEx(key,v)
opus.reg.getValue = _getValue
def _getKey(kp):
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,kp) as key:
rtn = Munch()
index = 0
length = winreg.QueryInfoKey(key)[1]
while index < length:
valueInfo = winreg.EnumValue(key,index)
rtn[valueInfo[0]] = Munch()
rtn[valueInfo[0]].value = valueInfo[1]
rtn[valueInfo[0]].type = valueInfo[2]
index = index + 1
return rtn
opus.reg.getKey = _getKey
def _setValue(kp,key,vt,value):
print("owo")