def __init__(self, **kwargs):
python_version = kwargs.pop('python', '3.4')
python_path = None
for node in ('Wow6432Node\\', ''):
try:
key = compat_winreg.OpenKey(
compat_winreg.HKEY_LOCAL_MACHINE,
r'SOFTWARE\%sPython\PythonCore\%s\InstallPath' % (node, python_version))
try:
python_path, _ = compat_winreg.QueryValueEx(key, '')
finally:
compat_winreg.CloseKey(key)
break
except Exception:
pass
if not python_path:
raise BuildError('No such Python version: %s' % python_version)
self.pythonPath = python_path
super(PythonBuilder, self).__init__(**kwargs)
python类HKEY_LOCAL_MACHINE的实例源码
def unregister(classobj):
import _winreg
subKeyCLSID = "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\%38s" % classobj._reg_clsid_
try:
hKey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
subKey = _winreg.DeleteValue( hKey, "ButtonText" )
_winreg.DeleteValue( hKey, "ClsidExtension" ) # for calling COM object
_winreg.DeleteValue( hKey, "CLSID" )
_winreg.DeleteValue( hKey, "Default Visible" )
_winreg.DeleteValue( hKey, "ToolTip" )
_winreg.DeleteValue( hKey, "Icon" )
_winreg.DeleteValue( hKey, "HotIcon" )
_winreg.DeleteKey( _winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
except WindowsError:
print "Couldn't delete Standard toolbar regkey."
else:
print "Deleted Standard toolbar regkey."
#
# test implementation
#
def __call__(self, name, sam=KEY_READ):
"""Get a registry key::
registry(r"HKEY_LOCAL_MACHINE\\Software")
registry("HKEY_LOCAL_MACHINE")("Software")
:rtype: :class:`PyHKey`
"""
if name in self.registry_base_keys:
key = self.registry_base_keys[name]
if sam != key.sam:
key = key.reopen(sam)
return key
if "\\" not in name:
raise ValueError("Unknow registry base key <{0}>".format(name))
base_name, subkey = name.split("\\", 1)
if base_name not in self.registry_base_keys:
raise ValueError("Unknow registry base key <{0}>".format(base_name))
return self.registry_base_keys[base_name](subkey, sam)
def register(classobj):
import _winreg
subKeyCLSID = "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\%38s" % classobj._reg_clsid_
try:
hKey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
subKey = _winreg.SetValueEx( hKey, "ButtonText", 0, _winreg.REG_SZ, classobj._button_text_ )
_winreg.SetValueEx( hKey, "ClsidExtension", 0, _winreg.REG_SZ, classobj._reg_clsid_ ) # reg value for calling COM object
_winreg.SetValueEx( hKey, "CLSID", 0, _winreg.REG_SZ, "{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}" ) # CLSID for button that sends command to COM object
_winreg.SetValueEx( hKey, "Default Visible", 0, _winreg.REG_SZ, "Yes" )
_winreg.SetValueEx( hKey, "ToolTip", 0, _winreg.REG_SZ, classobj._tool_tip_ )
_winreg.SetValueEx( hKey, "Icon", 0, _winreg.REG_SZ, classobj._icon_)
_winreg.SetValueEx( hKey, "HotIcon", 0, _winreg.REG_SZ, classobj._hot_icon_)
except WindowsError:
print "Couldn't set standard toolbar reg keys."
else:
print "Set standard toolbar reg keys."
def register(classobj):
import _winreg
subKeyCLSID = "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\%38s" % classobj._reg_clsid_
try:
hKey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
subKey = _winreg.SetValueEx( hKey, "ButtonText", 0, _winreg.REG_SZ, classobj._button_text_ )
_winreg.SetValueEx( hKey, "ClsidExtension", 0, _winreg.REG_SZ, classobj._reg_clsid_ ) # reg value for calling COM object
_winreg.SetValueEx( hKey, "CLSID", 0, _winreg.REG_SZ, "{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}" ) # CLSID for button that sends command to COM object
_winreg.SetValueEx( hKey, "Default Visible", 0, _winreg.REG_SZ, "Yes" )
_winreg.SetValueEx( hKey, "ToolTip", 0, _winreg.REG_SZ, classobj._tool_tip_ )
_winreg.SetValueEx( hKey, "Icon", 0, _winreg.REG_SZ, classobj._icon_)
_winreg.SetValueEx( hKey, "HotIcon", 0, _winreg.REG_SZ, classobj._hot_icon_)
except WindowsError:
print "Couldn't set standard toolbar reg keys."
else:
print "Set standard toolbar reg keys."
def unregister(classobj):
import _winreg
subKeyCLSID = "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\%38s" % classobj._reg_clsid_
try:
hKey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
subKey = _winreg.DeleteValue( hKey, "ButtonText" )
_winreg.DeleteValue( hKey, "ClsidExtension" ) # for calling COM object
_winreg.DeleteValue( hKey, "CLSID" )
_winreg.DeleteValue( hKey, "Default Visible" )
_winreg.DeleteValue( hKey, "ToolTip" )
_winreg.DeleteValue( hKey, "Icon" )
_winreg.DeleteValue( hKey, "HotIcon" )
_winreg.DeleteKey( _winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
except WindowsError:
print "Couldn't delete Standard toolbar regkey."
else:
print "Deleted Standard toolbar regkey."
#
# test implementation
#
def __init__(self, **kwargs):
python_version = kwargs.pop('python', '3.4')
python_path = None
for node in ('Wow6432Node\\', ''):
try:
key = compat_winreg.OpenKey(
compat_winreg.HKEY_LOCAL_MACHINE,
r'SOFTWARE\%sPython\PythonCore\%s\InstallPath' % (node, python_version))
try:
python_path, _ = compat_winreg.QueryValueEx(key, '')
finally:
compat_winreg.CloseKey(key)
break
except Exception:
pass
if not python_path:
raise BuildError('No such Python version: %s' % python_version)
self.pythonPath = python_path
super(PythonBuilder, self).__init__(**kwargs)
def patch_scsi_identifiers(self):
types = {
"DiskPeripheral": self.HDD_IDENTIFIERS,
"CdRomPeripheral": self.CDROM_IDENTIFIERS,
}
for row in itertools.product([0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]):
type_ = query_value(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port %d\\Scsi Bus %d\\Target Id %d\\Logical Unit Id %d" % row, "Type")
value = query_value(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port %d\\Scsi Bus %d\\Target Id %d\\Logical Unit Id %d" % row, "Identifier")
if not type_ or not value:
continue
value = value.lower()
if "vbox" in value or "vmware" in value or "qemu" in value or "virtual" in value:
if type_ in types:
new_value = random.choice(types[type_])
else:
log.warning("Unknown SCSI type (%s), disguising it with a random string", type_)
new_value = random_string(len(value))
set_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port %d\\Scsi Bus %d\\Target Id %d\\Logical Unit Id %d" % row,
"Identifier", REG_SZ, new_value)
def start(self):
if not self.options.get("dbgview"):
return
dbgview_path = os.path.join("bin", "dbgview.exe")
if not os.path.exists(dbgview_path):
log.error("DbgView.exe not found!")
return
# Make sure all logging makes it into DbgView.
set_regkey(
_winreg.HKEY_LOCAL_MACHINE, DebugPrintFilter,
"", _winreg.REG_DWORD, 0xffffffff
)
self.filepath = os.path.join(self.analyzer.path, "bin", "dbgview.log")
# Accept the EULA and enable Kernel Capture.
subprocess.Popen([
dbgview_path, "/accepteula", "/t", "/k", "/l", self.filepath,
])
log.info("Successfully started DbgView.")
def patch_scsi_identifiers(self):
types = {
"DiskPeripheral": self.HDD_IDENTIFIERS,
"CdRomPeripheral": self.CDROM_IDENTIFIERS,
}
for row in itertools.product([0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]):
type_ = query_value(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port %d\\Scsi Bus %d\\Target Id %d\\Logical Unit Id %d" % row, "Type")
value = query_value(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port %d\\Scsi Bus %d\\Target Id %d\\Logical Unit Id %d" % row, "Identifier")
if not type_ or not value:
continue
value = value.lower()
if "vbox" in value or "vmware" in value or "qemu" in value or "virtual" in value:
if type_ in types:
new_value = random.choice(types[type_])
else:
log.warning("Unknown SCSI type (%s), disguising it with a random string", type_)
new_value = random_string(len(value))
set_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port %d\\Scsi Bus %d\\Target Id %d\\Logical Unit Id %d" % row,
"Identifier", REG_SZ, new_value)
def register(classobj):
import _winreg
subKeyCLSID = "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\%38s" % classobj._reg_clsid_
try:
hKey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
subKey = _winreg.SetValueEx( hKey, "ButtonText", 0, _winreg.REG_SZ, classobj._button_text_ )
_winreg.SetValueEx( hKey, "ClsidExtension", 0, _winreg.REG_SZ, classobj._reg_clsid_ ) # reg value for calling COM object
_winreg.SetValueEx( hKey, "CLSID", 0, _winreg.REG_SZ, "{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}" ) # CLSID for button that sends command to COM object
_winreg.SetValueEx( hKey, "Default Visible", 0, _winreg.REG_SZ, "Yes" )
_winreg.SetValueEx( hKey, "ToolTip", 0, _winreg.REG_SZ, classobj._tool_tip_ )
_winreg.SetValueEx( hKey, "Icon", 0, _winreg.REG_SZ, classobj._icon_)
_winreg.SetValueEx( hKey, "HotIcon", 0, _winreg.REG_SZ, classobj._hot_icon_)
except WindowsError:
print "Couldn't set standard toolbar reg keys."
else:
print "Set standard toolbar reg keys."
def detect_vmware():
detected = False
# try:
# with OpenKey(HKEY_LOCAL_MACHINE,
# r"HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0") as key:
# print 1
# except Exception, e:
# print(e)
try:
with OpenKey(HKEY_LOCAL_MACHINE, r"SOFTWARE\\VMware, Inc.\\VMware Tools") as key:
detected = True
except Exception, e:
pass
## print(e)
windows_path = os.environ['WINDIR']
if os.path.isfile(os.path.join(windows_path, r"system32\drivers\vmmouse.sys")) or \
os.path.isfile(os.path.join(windows_path, r"system32\drivers\vmhgfs.sys")):
detected = True
return detected
def _find_msvc_in_registry(env,version):
if _is_py2:
import _winreg as winreg
else:
import winreg
vs_ver = str(version) + '.0'
vs_key = 'SOFTWARE\\Microsoft\\VisualStudio\\' + vs_ver + '\\Setup\\VS'
vc_key = 'SOFTWARE\\Microsoft\\VisualStudio\\' + vs_ver + '\\Setup\\VC'
vs_dir = _read_registry(winreg.HKEY_LOCAL_MACHINE, vs_key, 'ProductDir')
vc_dir = _read_registry(winreg.HKEY_LOCAL_MACHINE, vc_key, 'ProductDir')
# On a 64-bit host, look for a 32-bit installation
if (not vs_dir or not vc_dir):
vs_key = 'SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\' + \
vs_ver + '\\Setup\\VS'
vc_key = 'SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\' + \
vs_ver + '\\Setup\\VC'
vs_dir = _read_registry(winreg.HKEY_LOCAL_MACHINE,
vs_key, 'ProductDir')
vc_dir = _read_registry(winreg.HKEY_LOCAL_MACHINE,
vc_key, 'ProductDir')
return (vs_dir,vc_dir)
def _create_win(self):
try:
key = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
r'Software\Microsoft\Windows NT\CurrentVersion\Fonts')
except EnvironmentError:
try:
key = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
r'Software\Microsoft\Windows\CurrentVersion\Fonts')
except EnvironmentError:
raise FontNotFound('Can\'t open Windows font registry key')
try:
path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True)
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
path = self._lookup_win(key, self.font_name, STYLES[style])
if path:
self.fonts[style] = ImageFont.truetype(path, self.font_size)
else:
if style == 'BOLDITALIC':
self.fonts[style] = self.fonts['BOLD']
else:
self.fonts[style] = self.fonts['NORMAL']
finally:
_winreg.CloseKey(key)
def _get_effective_state_index():
"""
Get the state file index that's currently in use - deprecated
:return: index of the current effective state file
"""
hKey = OpenKey(HKEY_LOCAL_MACHINE, BITSStateFile.REG_BITS_KEY)
return QueryValueEx(hKey, BITSStateFile.REG_STATE_INDEX_VALUE)[0]
def _FindTimeZoneKey(self):
"""Find the registry key for the time zone name (self.timeZoneName)."""
# for multi-language compatability, match the time zone name in the
# "Std" key of the time zone key.
zoneNames = dict(self._get_indexed_time_zone_keys('Std'))
# Also match the time zone key name itself, to be compatible with
# English-based hard-coded time zones.
timeZoneName = zoneNames.get(self.timeZoneName, self.timeZoneName)
key = _RegKeyDict.open(_winreg.HKEY_LOCAL_MACHINE, self.tzRegKey)
try:
result = key.subkey(timeZoneName)
except:
raise ValueError('Timezone Name %s not found.' % timeZoneName)
return result
def _get_time_zone_key(subkey=None):
"Return the registry key that stores time zone details"
key = _RegKeyDict.open(_winreg.HKEY_LOCAL_MACHINE, TimeZoneInfo.tzRegKey)
if subkey:
key = key.subkey(subkey)
return key
def _find_exe_in_registry(self):
try:
from _winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER
except ImportError:
from winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER
import shlex
keys = (
r"SOFTWARE\Classes\FirefoxHTML\shell\open\command",
r"SOFTWARE\Classes\Applications\firefox.exe\shell\open\command"
)
command = ""
for path in keys:
try:
key = OpenKey(HKEY_LOCAL_MACHINE, path)
command = QueryValue(key, "")
break
except OSError:
try:
key = OpenKey(HKEY_CURRENT_USER, path)
command = QueryValue(key, "")
break
except OSError:
pass
else:
return ""
if not command:
return ""
return shlex.split(command)[0]
def DllRegisterServer():
comclass = IEToolbar
# register toolbar with IE
try:
print "Trying to register Toolbar.\n"
hkey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer\\Toolbar" )
subKey = _winreg.SetValueEx( hkey, comclass._reg_clsid_, 0, _winreg.REG_BINARY, "\0" )
except WindowsError:
print "Couldn't set registry value.\nhkey: %d\tCLSID: %s\n" % ( hkey, comclass._reg_clsid_ )
else:
print "Set registry value.\nhkey: %d\tCLSID: %s\n" % ( hkey, comclass._reg_clsid_ )
# TODO: implement reg settings for standard toolbar button
# unregister plugin
def DllUnregisterServer():
comclass = IEToolbar
# unregister toolbar from internet explorer
try:
print "Trying to unregister Toolbar.\n"
hkey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer\\Toolbar" )
_winreg.DeleteValue( hkey, comclass._reg_clsid_ )
except WindowsError:
print "Couldn't delete registry value.\nhkey: %d\tCLSID: %s\n" % ( hkey, comclass._reg_clsid_ )
else:
print "Deleting reg key succeeded.\n"
# entry point
def _listen(self):
""" Listen for information from a client and performs
actions related to the windows registry """
registry = Registry()
listener = Listener(('localhost', self.port), authkey=self.password)
conn = listener.accept()
msg = conn.recv()
if type(msg) is list and len(msg) == 2:
# Deleting debugger key
debug_path = self.DEBUG_KEY + msg[0]
k = registry.open_key(HKLM, debug_path)
registry.del_value(k, "debugger")
# Deleting the bad path
k = registry.open_key(HKCU, msg[1])
if k:
self.brush.color("[!!] POSSIBLE UAC BYPASS IN YOUR SYSTEM\n", 'RED')
registry.delete_key(HKCU, msg[1])
ctypes.windll.user32.MessageBoxA(
None, "UAC BYPASS DETECTADO Y MITIGADO. EJECUCION SEGURA DEL BINARIO", "PELIGRO!", 0)
os.system(msg[0])
# Setting the debugger key before breaking connection
k = registry.open_key(HKLM, debug_path)
payload = self.build_payload(msg[0][:-3] + "pyw")
registry.create_value(k,
"debugger",
payload)
print "[+] Closing the listener"
conn.close()
listener.close()
def add_debugger(self, registry, binlist):
""" Adds debugger registry key for
each of the processes in the list """
for binary in binlist:
path = self.DEBUG_KEY + binary
k = registry.open_key(HKLM, path)
if not(k):
k = registry.create_key(HKLM, path)
payload = self.build_payload(binary[:-3] + "pyw")
registry.create_value(k,
"debugger",
payload)
def del_debugger(self, registry, binlist):
""" Deletes debugger registry key for
each of the processes in the list """
for binary in binlist:
path = self.DEBUG_KEY + binary
k = registry.open_key(HKLM, path)
if not(k):
return
registry.del_value(k, "debugger")
def __init__(self, logCallback):
MSstore = r"Software\Microsoft\SystemCertificates"
GPstore = r"Software\Policy\Microsoft\SystemCertificates"
self.regKeys = {
"CU_STORE": [reg.HKEY_CURRENT_USER, MSstore],
"LM_STORE": [reg.HKEY_LOCAL_MACHINE, MSstore],
"USER_STORE": [reg.HKEY_USERS, MSstore],
"CU_POLICY_STORE": [reg.HKEY_CURRENT_USER, GPstore],
"LM_POLICY_STORE": [reg.HKEY_LOCAL_MACHINE, GPstore]
}
self.logCallback = logCallback
def _watch_thread_dispatcher(self):
MSstore = r"Software\Microsoft\SystemCertificates"
GPstore = r"Software\Policy\Microsoft\SystemCertificates"
regKeys = {
"CU_STORE": [win32con.HKEY_CURRENT_USER, MSstore],
"LM_STORE": [win32con.HKEY_LOCAL_MACHINE, MSstore],
"USER_STORE": [win32con.HKEY_USERS, MSstore],
"CU_POLICY_STORE": [win32con.HKEY_CURRENT_USER, GPstore],
"LM_POLICY_STORE": [win32con.HKEY_LOCAL_MACHINE, GPstore]
}
watchKeys = self.database.get_watch_keys()
for regKey in watchKeys:
self._log("Dispatcher preparing watch thread for key: %s" % regKey, messageType="DEBUG")
key = regKey.split("/")
storeName = key.pop(0)
additionalValue = "\\%s" % "\\".join(key)
keystore = regKeys[storeName]
keyName = keystore[1] + additionalValue
t = threading.Thread(target=self._watch_thread, args=(keystore[0], keyName, regKey,
self._watch_thread_callback,))
self.watchThreads.append(t)
self._log("Thread prepared.", messageType="DEBUG")
self._log("Launching %d threads..." % len(self.watchThreads), messageType="DEBUG")
for t in self.watchThreads:
t.start()
self._log("Dispatcher completed.", messageType="DEBUG")
return
def _create_win(self):
try:
key = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
r'Software\Microsoft\Windows NT\CurrentVersion\Fonts')
except EnvironmentError:
try:
key = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
r'Software\Microsoft\Windows\CurrentVersion\Fonts')
except EnvironmentError:
raise FontNotFound('Can\'t open Windows font registry key')
try:
path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True)
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
path = self._lookup_win(key, self.font_name, STYLES[style])
if path:
self.fonts[style] = ImageFont.truetype(path, self.font_size)
else:
if style == 'BOLDITALIC':
self.fonts[style] = self.fonts['BOLD']
else:
self.fonts[style] = self.fonts['NORMAL']
finally:
_winreg.CloseKey(key)
def _find_exe_in_registry(self):
try:
from _winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER
except ImportError:
from winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER
import shlex
keys = (
r"SOFTWARE\Classes\FirefoxHTML\shell\open\command",
r"SOFTWARE\Classes\Applications\firefox.exe\shell\open\command"
)
command = ""
for path in keys:
try:
key = OpenKey(HKEY_LOCAL_MACHINE, path)
command = QueryValue(key, "")
break
except OSError:
try:
key = OpenKey(HKEY_CURRENT_USER, path)
command = QueryValue(key, "")
break
except OSError:
pass
else:
return ""
if not command:
return ""
return shlex.split(command)[0]
def _create_win(self):
try:
key = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
r'Software\Microsoft\Windows NT\CurrentVersion\Fonts')
except EnvironmentError:
try:
key = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
r'Software\Microsoft\Windows\CurrentVersion\Fonts')
except EnvironmentError:
raise FontNotFound('Can\'t open Windows font registry key')
try:
path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True)
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
path = self._lookup_win(key, self.font_name, STYLES[style])
if path:
self.fonts[style] = ImageFont.truetype(path, self.font_size)
else:
if style == 'BOLDITALIC':
self.fonts[style] = self.fonts['BOLD']
else:
self.fonts[style] = self.fonts['NORMAL']
finally:
_winreg.CloseKey(key)
def __init__(self, scope):
self.scope = scope
if scope == 'user':
self.root = winreg.HKEY_CURRENT_USER
self.subkey = 'Environment'
else:
self.root = winreg.HKEY_LOCAL_MACHINE
self.subkey = r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
def DllRegisterServer():
comclass = IEToolbar
# register toolbar with IE
try:
print "Trying to register Toolbar.\n"
hkey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer\\Toolbar" )
subKey = _winreg.SetValueEx( hkey, comclass._reg_clsid_, 0, _winreg.REG_BINARY, "\0" )
except WindowsError:
print "Couldn't set registry value.\nhkey: %d\tCLSID: %s\n" % ( hkey, comclass._reg_clsid_ )
else:
print "Set registry value.\nhkey: %d\tCLSID: %s\n" % ( hkey, comclass._reg_clsid_ )
# TODO: implement reg settings for standard toolbar button
# unregister plugin