Exemple #1
0
def test_write_entry() -> None:
    with WinRegistry() as client:
        client.create_key(TEST_REG_PATH)
        client.write_entry(TEST_REG_PATH, "remove_me", "test")
        test_entry = client.read_entry(TEST_REG_PATH, "remove_me")
        assert test_entry.value == "test"
        client.delete_entry(TEST_REG_PATH, "remove_me")
 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)
Exemple #3
0
def test_get_key_handle() -> None:
    with WinRegistry() as reg:
        # pylint: disable=protected-access
        handler = reg._get_handler(
            r"HKCU\SOFTWARE",
            access=KEY_READ,
            key_wow64_32key=False,
        )
        assert handler
Exemple #4
0
def test_delete_entry() -> None:
    with WinRegistry() as client:
        client.create_key(TEST_REG_PATH)
        client.write_entry(TEST_REG_PATH, "remove_me", "test")
        client.read_entry(TEST_REG_PATH, "remove_me")
        client.delete_entry(TEST_REG_PATH, "remove_me")
        try:
            client.read_entry(TEST_REG_PATH, "remove_me")
            raise AssertionError
        except FileNotFoundError:
            pass
Exemple #5
0
def test_delete_key_tree() -> None:
    reg_key = r"HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\test"
    with WinRegistry() as client:
        try:
            client.read_key(reg_key)
            raise AssertionError
        except FileNotFoundError:
            pass
        client.create_key(reg_key + "\\test1\\test3")
        client.write_entry(reg_key + "\\test1", "remove_me", "test")
        client.delete_key_tree(reg_key)
        try:
            client.read_key(reg_key)
            raise AssertionError
        except FileNotFoundError:
            pass
Exemple #6
0
def test_delete_key() -> None:
    reg_key = r"HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\test"
    with WinRegistry() as client:
        try:
            client.read_key(
                r"HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\test")
            raise AssertionError
        except FileNotFoundError:
            pass
        client.create_key(reg_key)
        client.delete_key(
            r"HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\test")
        try:
            client.read_key(
                r"HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\test")
            raise AssertionError
        except FileNotFoundError:
            pass
Exemple #7
0
def test_create_key() -> None:
    reg_key = r"HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\test\foo"
    with WinRegistry() as client:
        try:
            data = client.read_key(
                r"HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\test")
            raise AssertionError
        except FileNotFoundError:
            pass
        client.create_key(reg_key)
        data = client.read_key(
            r"HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\test")
        assert len(data.reg_keys) == 1, data
        assert "foo" in data.reg_keys, data
        client.delete_key(
            r"HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\test\foo")
        client.delete_key(
            r"HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\test")
Exemple #8
0
def test_read_key() -> None:
    reg_key = r"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    with WinRegistry() as client:
        data = client.read_key(reg_key)
        assert data.entries
        assert data.reg_keys
Exemple #9
0
def test_read_entry() -> None:
    reg_key = r"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    with WinRegistry() as client:
        software_type = client.read_entry(reg_key, "SoftwareType")
    assert software_type.value == "System"