def create_local_gpo(): #key = winreg.Key("HKEY_LOCAL_MACHINE", r"SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State", "Machine") key = winreg.Key("HKEY_LOCAL_MACHINE", r"SOFTWARE\Policies\Microsoft\Windows\System", "Scripts") #if not winreg.sub_key_exists("HKEY_LOCAL_MACHINE", r"SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts"): if not winreg.sub_key_exists("HKEY_LOCAL_MACHINE", "SOFTWARE\Policies\Microsoft\Windows\System\Scripts"): key1 = key.create_key("Scripts") else: #key1 = winreg.Key("HKEY_LOCAL_MACHINE", r"SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine", "Scripts") key1 = winreg.Key("HKEY_LOCAL_MACHINE", r"SOFTWARE\Policies\Microsoft\Windows\System", "Scripts") #if not winreg.sub_key_exists("HKEY_LOCAL_MACHINE", r"SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown"): if not winreg.sub_key_exists("HKEY_LOCAL_MACHINE", r"SOFTWARE\Policies\Microsoft\Windows\System\Scripts\Shutdown"): key2 = key1.create_key("Shutdown") else: #key2 = winreg.Key("HKEY_LOCAL_MACHINE", r"SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts", "Shutdown") key2 = winreg.Key("HKEY_LOCAL_MACHINE", r"SOFTWARE\Policies\Microsoft\Windows\System\Scripts", "Shutdown") #if not winreg.sub_key_exists("HKEY_LOCAL_MACHINE", r"SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0"): if not winreg.sub_key_exists("HKEY_LOCAL_MACHINE", r"SOFTWARE\Policies\Microsoft\Windows\System\Scripts\Shutdown\0"): key3 = key2.create_key("Shutdown") key3.create_value("GPO-ID", winreg.REG_SZ, "LocalGPO") key3.create_value("SOM-ID", winreg.REG_SZ, "Local") key3.create_value("FileSysPath", winreg.REG_SZ, "C:\\WINDOWS\\System32\\GroupPolicy\\Machine") key3.create_value("DisplayName", winreg.REG_SZ, "Richtlinien der lokalen Gruppe") key3.create_value("DisplayName", winreg.REG_SZ, "Richtlinien der lokalen Gruppe") else: #key3 = winreg.Key("HKEY_LOCAL_MACHINE", r"SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown", "0") key3 = winreg.Key("HKEY_LOCAL_MACHINE", r"SOFTWARE\Policies\Microsoft\Windows\System\Scripts\Shutdown", "0")
def get_key(key, subkey, mode=None): 'Return the specified subkey.' key = winreg.Key(key) for subkey in subkey.split('\\'): if subkey not in key.keys: key.keys = subkey key = key.keys[subkey] return winreg.Key(key, mode=mode)
def _export(key, ignore): 'Export all subkeys in key to globals.' try: GLOBAL = globals() root = _wi.Key(_wi.HKEY.CURRENT_USER, key) for key in root.keys: GLOBAL[key] = obj = _Virtual(_wi.Key(root, key, _wi.KEY.ALL_ACCESS)) attr = getattr(_in, key) delattr(_in, key) if key not in ignore: for key in obj: assert type(obj[key]) == type(attr[key]) del attr[key] assert not attr assert not sum(map(lambda name: name.isupper(), dir(_in))) except: _TK.Tk().withdraw() _MB.showerror('Error', 'Please install this program first.') raise SystemExit, 1
def getValueFromReg(key, valuename, default, hive=winreg.HKLM): """Pass valuename=None to get the (default) value.""" try: key=winreg.Key(hive, key) except winreg.KeyNotFound: return default if valuename is None: return key.value try: return key.values[valuename].value except winreg.ValueNotFound: return default
def __init__(self): self._scripts = [] self._index = -1 create_local_gpo() #self._key = winreg.Key("HKEY_LOCAL_MACHINE", r"SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown", "0") self._key = winreg.Key("HKEY_LOCAL_MACHINE", r"SOFTWARE\Policies\Microsoft\Windows\System\Scripts\Shutdown", "0") self._next_script_nr = 0 for sub_key in self._key: if isinstance(sub_key, winreg.Key): key_nr = int(sub_key.get_name()) if self._next_script_nr < key_nr: self._next_script_nr = key_nr script = sub_key["Script"].data parameters = sub_key["Parameters"].data exec_time = sub_key["ExecTime"].data self._scripts.append(ShutdownScript(key_nr, script, parameters, exec_time))
def delete(key, subkey): 'Delete key and all subkeys.' parent = winreg.Key(winreg.HKEY.CURRENT_USER, key) del parent.keys[subkey].keys del parent.keys[subkey] return key, parent