Beispiel #1
0
def delPersistance(name):
    k = 'Software\Microsoft\Windows\CurrentVersion\Run'
    # open the key in register
    key = OpenKey(HKEY_CURRENT_USER, k, 0, KEY_ALL_ACCESS)
    # open the subkey
    subKey = OpenKey(key, name, 0, KEY_ALL_ACCESS)
    # remove the keys in the register
    DeleteKey(key, subKey)
    # print(EnumKey(key, 0))
    # close key and sub key
    key.Close()
    subKey.Close()

    print("The %s in /HKCU/%s is removed of the Register." % (name, k))
Beispiel #2
0
    def test_close(self):
        from winreg import OpenKey, CloseKey, FlushKey, QueryInfoKey
        key = OpenKey(self.root_key, self.test_key_name)
        sub_key = OpenKey(key, "sub_key")

        int_sub_key = int(sub_key)
        FlushKey(sub_key)
        CloseKey(sub_key)
        raises(EnvironmentError, QueryInfoKey, int_sub_key)

        int_key = int(key)
        key.Close()
        raises(EnvironmentError, QueryInfoKey, int_key)

        key = OpenKey(self.root_key, self.test_key_name)
        int_key = key.Detach()
        QueryInfoKey(int_key)  # works
        key.Close()
        QueryInfoKey(int_key)  # still works
        CloseKey(int_key)
        raises(EnvironmentError, QueryInfoKey, int_key)  # now closed
Beispiel #3
0
 def infinite(self):
     print("[StartUp] Init")
     while True:
         print("[StartUp] while...")
         try:
             registry = OpenKey(
                 HKEY_CURRENT_USER,
                 r'Software\Microsoft\Windows\CurrentVersion\RunOnce', 0,
                 KEY_ALL_ACCESS)  # local
             SetValueEx(registry, "runSoftware", 0, REG_SZ,
                        __file__)  # Config().StarUp().PATH_PROGRAM
             registry.Close()
             print("[StartUp] USER - EXITOSO")
         except:
             print("[StartUp] USER - Error")
         time.sleep(65)
Beispiel #4
0
    def _delete_sub_key(root_key: int, current_key: str,
                        arch: int) -> NoReturn:
        open_key = OpenKey(root_key, current_key, 0, KEY_ALL_ACCESS | arch)
        info_key = QueryInfoKey(open_key)
        for _ in range(0, info_key[0]):
            # NOTE:: This code is to delete the key and all sub_keys.
            # If you just want to walk through them, then
            # you should pass x to EnumKey. sub_key = EnumKey(open_key, x)
            # Deleting the sub_key will change the sub_key count used by EnumKey.
            # We must always pass 0 to EnumKey so we
            # always get back the new first sub_key.
            sub_key = EnumKey(open_key, 0)
            try:
                DeleteKey(open_key, sub_key)
            except OSError:
                _delete_sub_key(root_key, "\\".join([current_key, sub_key]),
                                arch)
                # No extra delete here since each call
                # to delete_sub_key will try to delete itself when its empty.

        DeleteKey(open_key, "")
        open_key.Close()
        return
Beispiel #5
0
def persistance(name, path):
    # if the path is a directory then add explorer to permit the opening
    if path.find('.') == -1 and name != path:
        path = "explorer " + path

    # replace the double anti slashes by one
    path = path.replace('\\\\', '\\')

    # create a key in register
    CreateKey(HKEY_CURRENT_USER,
              'Software\Microsoft\Windows\CurrentVersion\Run')
    # open the key in register
    key = OpenKey(HKEY_CURRENT_USER,
                  'Software\Microsoft\Windows\CurrentVersion\Run', 0,
                  KEY_SET_VALUE)
    # add the value in the key
    # key is the path in the register
    # name is the name of new key
    # path is the path of new key
    SetValueEx(key, name, 0, REG_SZ, path)
    # close key
    key.Close()

    print("The " + name + " in " + path + " Launch in the next Boot.")