def getImageVersion(): reg = Reg() path = r'HKLM\SOFTWARE\TheThirdfloor' try: reg.read_key(path) iv = reg.read_value(path, 'ImageVersion') return iv['data'] except: return 0
def initReg(): reg = Reg() if "vkparser" in reg.read_key(r'HKEY_CURRENT_USER\SOFTWARE')['keys']: writeReg("none") return reg.create_key(r'HKEY_CURRENT_USER\SOFTWARE\vkparser') writeReg("none")
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 _check_chrome_version(): """ 利用產品註冊碼找尋Chrome的版本號,並去掉最後一碼 :return: Chrome版本號 【String】 """ reg = Reg() path = r"HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" chrome_version = None for reg_value in reg.read_key(path)["values"]: if reg_value["value"].lower() == "version": chrome_version = reg_value["data"] # 去掉未一碼的version chrome_version = chrome_version.split(".") del chrome_version[-1] chrome_version = ".".join(chrome_version) return chrome_version
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
def setup_engine_paths(self, custom_engine_path=''): # Assume the engine is just back from our project directory. Or check the registry to see where # it actually resides. if self.UE4EnginePath != '' and custom_engine_path == '': return True # No need, already setup result = True # Initially do the obvious search, one path back from the project directory self.UE4EnginePath = os.path.abspath( os.path.join(self.uproject_dir_path, self.engine_path_name)) if custom_engine_path != '': self.UE4EnginePath = custom_engine_path if self.UE4EngineKeyName != '' and not os.path.isdir( self.UE4EnginePath): # search the registry and see if the engine is registered elsewhere reg = Reg() try: registered_engines = reg.read_key( self.UE4EngineBuildsReg)['values'] for engine in registered_engines: if engine['value'] == self.UE4EngineKeyName: # this is it! self.UE4EnginePath = engine['data'] break else: self.UE4EnginePath = '' result = False except Exception: # No keys exist, fresh install! self.UE4EnginePath = '' result = False else: result = check_engine_dir_valid(self.UE4EnginePath) if result: self.editor_running = is_editor_running(self.UE4EnginePath) # Set all absolute paths to unreal tools self.UE4GenProjFilesPath = str( Path(self.UE4EnginePath, 'Engine\\Build\\BatchFiles\\GenerateProjectFiles.bat')) self.UE4GitDependenciesPath = str( Path(self.UE4EnginePath, 'Engine\\Binaries\\DotNET\\GitDependencies.exe')) self.UE4EnginePrereqPath = str( Path(self.UE4EnginePath, 'Engine\\Extras\\Redist\\en-us\\UE4PrereqSetup_x64.exe')) self.UE4UBTPath = str( Path(self.UE4EnginePath, 'Engine\\Binaries\\DotNET\\UnrealBuildTool.exe')) self.UE4RunUATBatPath = str( Path(self.UE4EnginePath, 'Engine\\Build\\BatchFiles\\RunUAT.bat')) self.UE4BuildBatchPath = str( Path(self.UE4EnginePath, 'Engine\\Build\\BatchFiles\\Build.bat')) self.UE4CleanBatchPath = str( Path(self.UE4EnginePath, 'Engine\\Build\\BatchFiles\\Clean.bat')) self.UE4EditorPath = str( Path(self.UE4EnginePath, 'Engine\\Binaries\\Win64\\UE4Editor.exe')) self.UE4VersionSelectorPath = str( Path( self.UE4EnginePath, 'Engine\\Binaries\\Win64\\UnrealVersionSelector-Win64-Shipping.exe' )) return result
def get_Truerngs_from_registry(): reg = Reg() usb_serial_devices = reg.read_key( r'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\usbser\Enum' ) devices_values = usb_serial_devices["values"] serialNumber = 'None' index = 0 devicesFound = [] # Loop through for x in devices_values: try: serialNumber = 'None' # TrueRNG V1/V2/V3 if 'VID_04D8&PID_F5FE' in x["data"]: temp = x["data"].split('\\') vidpid = temp[1] keyid = temp[2] newkey = 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\USB\\' + str( vidpid) + '\\' + str(keyid) device_info = reg.read_key(newkey)["values"] deviceType = 'TrueRNG V1/V2/V3' for k in device_info: if k['value'] == "FriendlyName": FriendlyName = k['data'] if k['value'] == "HardwareID": vidpidrev = k['data'][0].split('\\')[1].split('&') devicesFound.append(deviceType + ' : ' + \ vidpidrev[2] + ' : No SN : ' + FriendlyName) # TrueRNGpro (FW > 1.39) # USB Class 0A if 'VID_16D0&PID_0AA0\\' in x["data"]: temp = x["data"].split('\\') vidpid = temp[1] keyid = temp[2] newkey = 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\USB\\' + str( vidpid) + '\\' + str(keyid) device_info = reg.read_key(newkey)["values"] deviceType = 'TrueRNGpro (V1) ' for k in device_info: if k['value'] == "FriendlyName": FriendlyName = k['data'] if k['value'] == "HardwareID": vidpidrev = k['data'][0].split('\\')[1].split('&') devicesFound.append(deviceType + ' : ' + \ vidpidrev[2] + ' : ' + keyid + ' : ' + FriendlyName) # TrueRNGpro (FW <= 1.39) # USB Class 02 if 'VID_16D0&PID_0AA0&MI_00\\' in x["data"]: temp = x["data"].split('\\') vidpid = temp[1] keyid = temp[2] newkey = 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\USB\\' + str( vidpid) + '\\' + str(keyid) device_info = reg.read_key(newkey)["values"] deviceType = 'TrueRNGpro (V1) ' for k in device_info: if k['value'] == "FriendlyName": FriendlyName = k['data'] if k['value'] == "HardwareID": vidpidrev = k['data'][0].split('\\')[1].split('&') # Find the info of the parent device since Windows doesn't populate the serial number into the child newkey = 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\USB\\VID_16D0&PID_0AA0' device_keys = reg.read_key(newkey)['keys'] # Iterate through the keys to find our device by it's key id for j in device_keys: newkey = 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\USB\\VID_16D0&PID_0AA0\\' + j temp_device = reg.read_key(newkey)['values'] for a in temp_device: if 'ParentIdPrefix' in a['value']: # If we have the right key entry if a['data'] in keyid: serialNumber = j if serialNumber != 'None': devicesFound.append(deviceType + ' : ' + \ vidpidrev[2] + ' : ' + serialNumber + ' : ' + FriendlyName) else: devicesFound.append(deviceType + ' : ' + \ vidpidrev[2] + ' : ' + keyid + ' : ' + FriendlyName) # TrueRNGpro V2 (FW > 1.39) # USB Class 0A if 'VID_04D8&PID_EBB5' in x["data"]: temp = x["data"].split('\\') vidpid = temp[1] keyid = temp[2] newkey = 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\USB\\' + str( vidpid) + '\\' + str(keyid) device_info = reg.read_key(newkey)["values"] deviceType = 'TrueRNGpro (V2) ' for k in device_info: if k['value'] == "FriendlyName": FriendlyName = k['data'] if k['value'] == "HardwareID": vidpidrev = k['data'][0].split('\\')[1].split('&') devicesFound.append(deviceType + ' : ' + \ vidpidrev[2] + ' : ' + keyid + ' : ' + FriendlyName) except: i = 1 return devicesFound
# from winregistry import WinRegistry as Reg from pprint import pprint reg = Reg() print("-" * 10) path = r'HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0' try: print(f"Attempting to read {path}") pprint(reg.read_key(path), width=100) except: pass print("-" * 10) path = r'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSBuild\ToolsVersions\4.0' try: print(f"Attempting to read {path}") pprint(reg.read_key(path), width=100) except: pass print("-" * 10)
def _load_from_windows(self): reg = Reg() path = r"HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" self._reg_hklm = reg.read_key(path)['values'] path = r"HKCU\Environment" self._reg_hkcu = reg.read_key(path)['values']