def enforce(self): f = open("rollback.txt", "w") reg = Reg() for i in range(len(structure)): try: path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] x = reg.read_value(path, y)['data'] print(x, file=f) except: print('-1', file=f) pass # doing nothing on exception f.close() global rb rb = [] with open('rollback.txt') as my_file: for line in my_file: rb.append(line.rstrip()) for i in self.list.curselection(): z = (item_type[i])[1:] if z == 'REGISTRY_SETTING': path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] value_data = int((val_data[i])[2:-1]) x = reg.read_value(path, y)['data'] if x != value_data: reg.write_value(path, y, value_data, 'REG_DWORD')
def SvcDoRun(self): self.is_running = True servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, ("hello", "")) #current_location = str(os.path.abspath(os.path.dirname(sys.argv[0]))) # 현재 위치 체크 while self.is_running: # self.is_running이 True인 경우에만 while 실행 rc = win32event.WaitForSingleObject(self.hWaitStop, 5000) if rc == win32event.WAIT_OBJECT_0: break else: #subprocess.Popen([current_location + "\\Main.exe"]) # 현재 경로에 위치한 Main.exe # TEST #f = open('e:/download/1/a.log', 'a') #f.write(datetime.datetime.now().isoformat()) #f.close() reg = WinRegistry() path = r'HKCU\Control Panel\Desktop' keyvalue = reg.read_key(path) for v in keyvalue['values']: if v['value'] == 'SCRNSAVE.EXE': if v['data'] != 'c:\\Windows\\System32\\PhotoScreensaver.scr': reg.delete_value(path, 'SCRNSAVE.EXE') reg.write_value( path, 'SCRNSAVE.EXE', 'c:\\Windows\\System32\\PhotoScreensaver.scr') time.sleep(60)
def update_registry(self): a = self._db.cursor().execute( "SELECT branch, value, data from registry WHERE selected='*'" ).fetchall() reg = Reg() success = [] errors = [] for (key, value, data) in a: _key = '' if key == 'HKCU': _key = r"HKCU\Environment" elif key == 'HKLM': _key = r"HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" try: reg.write_value(_key, value, data, 'REG_SZ') except WindowsError: errors.append(value) else: success.append(value) path = reg.read_value(_key, 'PATH')['data'] # print(path) _path = ';' + path + ';' _path = _path.replace(';%' + value + '%;', ';') _path = _path + f';%{value}%;' path = _path[1:-1:] path = path.replace(';;', ';') path = path.replace(';;', ';') try: reg.write_value(_key, 'PATH', path, 'REG_SZ') except WindowsError: errors.append(f'PATH for {value}') return (success, errors)
def rollback(self): reg = Reg() for i in range(len(structure)): z = (item_type[i])[1:] if (z == 'REGISTRY_SETTING') & (int(rb[i]) != -1): path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] reg.write_value(path, y, int(rb[i]), 'REG_DWORD')
def rollback(self): reg = Reg() for i in self.list.curselection(): z = (item_type[i])[1:] if z == 'REGISTRY_SETTING': path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] reg.write_value(path, y, int(rb[i]), 'REG_DWORD')
def enforce(self): reg = Reg() for i in self.list.curselection(): z = (item_type[i])[1:] if z == 'REGISTRY_SETTING': path = (reg_key[i])[2:-1] y = reg.read_value(path, (reg_item[i])[2:-1])['value'] value_data = int((val_data[i])[2:-1]) x = reg.read_value(path, y)['data'] if x != value_data: reg.write_value(path, y, value_data, 'REG_DWORD')
def register_project_engine(config, prompt_path=True): """ Register the projects engine :return: True on success """ reg = Reg() try: registered_engines = reg.read_key(config.UE4EngineBuildsReg)['values'] for engine in registered_engines: eng_val = engine['value'] # type:str if eng_val.startswith('{') and eng_val.endswith('}'): click.secho("Removing arbitrary Engine Association {0}".format( eng_val)) reg.delete_value(config.UE4EngineBuildsReg, engine['value']) except Exception: # No entries yet, all good! pass if check_engine_dir_valid(config.UE4EnginePath): click.secho('Setting engine registry key {0} to {1}'.format( config.UE4EngineKeyName, config.UE4EnginePath)) try: reg.create_key(config.UE4EngineBuildsReg) except Exception: pass reg.write_value(config.UE4EngineBuildsReg, config.UE4EngineKeyName, config.UE4EnginePath, 'REG_SZ') elif prompt_path: my_engine_path = input('Enter Engine Path: ') if check_engine_dir_valid(my_engine_path): click.secho('Setting engine registry key {0} to {1}'.format( config.UE4EngineKeyName, my_engine_path)) reg.write_value(config.UE4EngineBuildsReg, config.UE4EngineKeyName, my_engine_path, 'REG_SZ') else: print_error( "Could not find engine path, make sure you type the full path!" ) return False else: print_error("Could not find engine path!") return False return True
class Keywords(object): def __init__(self, host=None): self.reg = Reg(host) def read_registry_key(self, key, key_wow64_32key=False): """ Reading registry key """ resp = self.reg.read_key(key, key_wow64_32key) return resp def create_registry_key(self, key, key_wow64_32key=False): """ Creating registry key """ self.reg.create_key(key, key_wow64_32key) def delete_registry_key(self, key, key_wow64_32key=False): """ Deleting registry key """ self.reg.delete_key(key, key_wow64_32key) def read_registry_value(self, key, value, key_wow64_32key=False): """ Reading value from registry """ return self.reg.read_value(key, value, key_wow64_32key) def write_registry_value(self, key, value, data=None, reg_type='REG_SZ', key_wow64_32key=False): """ Writing (or creating) data in value """ self.reg.write_value(key, value, data, reg_type, key_wow64_32key) def delete_registry_value(self, key, value, key_wow64_32key=False): """ Deleting value from registry """ self.reg.delete_value(key, value, key_wow64_32key)
def register_project_engine(config, prompt_path=True): """ Register the projects engine :return: True on success """ reg = Reg() # try: # registered_engines = reg.read_key(config.UE4EngineBuildsReg)['values'] # for engine in registered_engines: # eng_val = engine['value'] # type:str # if eng_val.startswith('{') and eng_val.endswith('}'): # click.secho("Removing arbitrary Engine Association {0}".format(eng_val)) # reg.delete_value(config.UE4EngineBuildsReg, engine['value']) # except Exception: # # No entries yet, all good! # pass if check_engine_dir_valid(config.UE4EnginePath): # Check if the engine is already registered try: registered_engines = reg.read_key(config.UE4EngineBuildsReg)['values'] for engine in registered_engines: if engine['value'] == config.UE4EngineKeyName: # Check if the data matches the engine path, if not, update the key if engine['data'] != config.UE4EnginePath: click.secho('Updating engine registry key {0}:{1} to {2}'.format(config.UE4EngineKeyName, engine['data'], config.UE4EnginePath)) click.secho('This is probably because the engine has been moved.') reg.write_value(config.UE4EngineBuildsReg, config.UE4EngineKeyName, config.UE4EnginePath, 'REG_SZ') return True except Exception: pass click.secho('Setting engine registry key {0} to {1}'.format(config.UE4EngineKeyName, config.UE4EnginePath)) try: reg.create_key(config.UE4EngineBuildsReg) except Exception: pass reg.write_value(config.UE4EngineBuildsReg, config.UE4EngineKeyName, config.UE4EnginePath, 'REG_SZ') elif prompt_path: my_engine_path = input('Enter Engine Path: ') if check_engine_dir_valid(my_engine_path): click.secho('Setting engine registry key {0} to {1}'.format(config.UE4EngineKeyName, my_engine_path)) reg.write_value(config.UE4EngineBuildsReg, config.UE4EngineKeyName, my_engine_path, 'REG_SZ') else: print_error("Could not find engine path, make sure you type the full path!") return False else: print_error("Could not find engine path to register!") return False return True
) choice = input('Do you really want to replace your HWID? [Y/N] : ') if choice == 'N': exit() elif choice == 'Y': os.system('cls') newHWID = '{' + input('Alright, enter your new HWID : ') + '}' os.system('cls') print('Are you sure you want to change your HWID to\n' + newHWID) choice2 = input('[Y/N] : ') if choice2 == 'N': exit() elif choice2 == 'Y': print('OK, Trying to write new HWID.') try: reg.write_value(path, 'HwProfileGuid', r'' + newHWID, 'REG_SZ') print('New HWID Saved!') except: print( 'Error! Failed to write new HWID, did you run this as admin?' ) exit() exit() else: print('Invalid Choice') exit() else: print('Invalid Choice') exit() elif choice == '2': print('Exited.')
import os import sys from winregistry import WinRegistry as Reg absPath = os.path.abspath(__file__) print('current file path', absPath) dirPath = os.path.dirname(absPath) print('computed file path', dirPath) filePath = os.path.join(dirPath, 'main.py') print('target file path', filePath) print('python location', sys.executable) reg = Reg() regPath = 'HKEY_CLASSES_ROOT\\*\\shell' videoViewerPath = regPath + '\\VideoViewer' reg.create_key(videoViewerPath) reg.write_value(videoViewerPath, '', data='Open by Video Viewer') commandPath = videoViewerPath + '\\command' reg.create_key(commandPath) reg.write_value(commandPath, '', data='"%s" "%s" "%s"' % (sys.executable, filePath, '%1'))