Beispiel #1
0
def set_reg():
    global set_reg_flag
    # full_path = sys.argv[0]
    full_path = sys.executable
    reg_root = win32con.HKEY_CLASSES_ROOT
    # 键的路径(具体路径自行修改)
    reg_path = "Directory\\Background\\shell\\wallpaper"
    reg_path_children = reg_path + "\\command"
    # 权限和参数设置
    reg_flags = win32con.WRITE_OWNER | win32con.KEY_WOW64_64KEY | win32con.KEY_ALL_ACCESS
    try:
        # 判断注册表中键值是否存在
        key = win32api.RegOpenKeyEx(reg_root, reg_path, 0, reg_flags)
    except Exception as e:
        print(e)
        key = None
    key_flag = False
    if key is None:
        key_flag = True
    else:
        key_flag = False
    if key_flag:
        try:
            # 直接创建(若存在,则为获取)
            key, _ = win32api.RegCreateKeyEx(reg_root, reg_path, reg_flags)
            win32api.RegSetValueEx(key, '', 0, win32con.REG_SZ, '更换壁纸')
            win32api.RegSetValueEx(key, 'Icon', 0, win32con.REG_SZ, full_path)
            win32api.RegCloseKey(key)
            key, _ = win32api.RegCreateKeyEx(reg_root, reg_path_children,
                                             reg_flags)
            win32api.RegSetValueEx(key, '', 0, win32con.REG_SZ, full_path)
            win32api.RegCloseKey(key)
            set_reg_flag = False
        except Exception as e:
            win32api.RegCloseKey(key)
            ctypes.windll.user32.MessageBoxW(0, '设置设置失败,为什么啊!!!',
                                             '右键快捷菜单设置(更换壁纸)', 0)
            set_reg_flag = False
    else:
        value, key_type = win32api.RegQueryValueEx(key, 'Icon')
        win32api.RegCloseKey(key)
        if value != full_path:
            key, _ = win32api.RegCreateKeyEx(reg_root, reg_path, reg_flags)
            win32api.RegSetValueEx(key, 'Icon', 0, win32con.REG_SZ, full_path)
            win32api.RegCloseKey(key)
            key, _ = win32api.RegCreateKeyEx(reg_root, reg_path_children,
                                             reg_flags)
            win32api.RegSetValueEx(key, '', 0, win32con.REG_SZ, full_path)
            win32api.RegCloseKey(key)
        set_reg_flag = False
def init_config():
    user_id_pattern = r"^20\d{10}$"
    try:
        reg = win32api.RegCreateKeyEx(
            win32con.HKEY_CURRENT_USER, "SOFTWARE\\LogDormWiFi",
            win32con.WRITE_OWNER | win32con.KEY_WOW64_64KEY
            | win32con.KEY_WRITE)
        print("请输入你的学号(20xxxxxxxxxx):", end='')
        userid = str(input())
        while (not (re.match(user_id_pattern, userid))):
            print("请输入你的[12位]学号(20xxxxxxxxxx):", end='')
            userid = str(input())
        win32api.RegSetValueEx(reg, "user_id", 0, win32con.REG_SZ, userid)
        print("请输入你的密码(默认为身份证后8位):", end='')
        password_ = str(input())
        win32api.RegSetValueEx(reg, "password", 0, win32con.REG_SZ, password_)
        win32api.RegCloseKey(reg)
        global wlanuserip_, wlanacip_, user_id, password
        #wlanuserip_ = tuple(wlanuserip)
        user_id = tuple(userid)
        password = tuple(password_)
    except Exception as E:
        print(E)
        if "Access is Denied" in str(E):
            print("初始化失败!\n")
        #win32api.RegSetValueEx (reg,"wlanuserip_", "", win32con.REG_SZ, keyValue)
    return
Beispiel #3
0
 def create_sub_key(self, sub_key_name):
     """create a sub key"""
     sub_key_path = os.path.join(self.path, sub_key_name)
     sub_key, _ = win32api.RegCreateKeyEx(
         self.root, sub_key_path, REG_FLAGS
     )
     return sub_key
Beispiel #4
0
def set_client_path():
    reg_root = win32con.HKEY_LOCAL_MACHINE
    reg_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AutoTax.exe"
    reg_flags = win32con.WRITE_OWNER | win32con.KEY_WOW64_64KEY | win32con.KEY_ALL_ACCESS

    config_path = os.path.dirname(os.path.realpath(sys.argv[0]))
    client_path = get_client_path()
    if str(client_path) != '' and str(client_path) == str(config_path):
        print('阻拦重复设置')
        return True

    try:
        #直接创建(若存在,则为获取)
        key, _ = win32api.RegCreateKeyEx(reg_root, reg_path, reg_flags)

        #设置项

        print('设置路径', config_path)
        win32api.RegSetValueEx(key, "Path", 0, win32con.REG_SZ, config_path)

        #关闭
        win32api.RegCloseKey(key)
        return True
    except:
        return False
Beispiel #5
0
    def _GetKey(self, key, subkey):
        (key, status) = win32api.RegCreateKeyEx(
            key, subkey, win32con.KEY_CREATE_SUB_KEY | win32con.KEY_QUERY_VALUE
            | win32con.KEY_SET_VALUE)

        if status == winnt.REG_CREATED_NEW_KEY:
            self._Changed = True

        return key
Beispiel #6
0
def set_reg(full_path):
    reg_root = win32con.HKEY_CLASSES_ROOT
    # 键的路径(具体路径自行修改)
    reg_path = "Directory\\Background\\shell\\wallpaper"
    reg_path_children = reg_path + "\\command"
    # 权限和参数设置
    reg_flags = win32con.WRITE_OWNER | win32con.KEY_WOW64_64KEY | win32con.KEY_ALL_ACCESS
    try:
        # 判断注册表中键值是否存在
        key = win32api.RegOpenKeyEx(reg_root, reg_path, 0, reg_flags)
    except Exception as e:
        print(e)
        key = None
    key_flag = False
    if key is None:
        key_flag = True
    else:
        key_flag = False
    if key_flag:
        try:
            # 直接创建(若存在,则为获取)
            key, _ = win32api.RegCreateKeyEx(reg_root, reg_path, reg_flags)
            win32api.RegSetValueEx(key, '', 0, win32con.REG_SZ, '更换壁纸')
            key, _ = win32api.RegCreateKeyEx(reg_root, reg_path_children,
                                             reg_flags)
            win32api.RegSetValueEx(key, '', 0, win32con.REG_SZ, full_path)
            ctypes.windll.user32.MessageBoxW(0, '设置成功,请点击右键查看!!!',
                                             '右键快捷菜单设置(更换壁纸)', 0)
        except Exception as e:
            print(e)
            ctypes.windll.user32.MessageBoxW(0, '设置设置失败,为什么啊!!!',
                                             '右键快捷菜单设置(更换壁纸)', 0)
    else:
        value = ctypes.windll.user32.MessageBoxW(0, '更换壁纸快捷键已经存在,点击确认替换',
                                                 '右键快捷菜单设置(更换壁纸)', 1)
        if value is 1:
            key, _ = win32api.RegCreateKeyEx(reg_root, reg_path_children,
                                             reg_flags)
            win32api.RegSetValueEx(key, '', 0, win32con.REG_SZ, full_path)
            ctypes.windll.user32.MessageBoxW(0, '设置成功,请点击右键查看!!!',
                                             '右键快捷菜单设置(更换壁纸)', 0)
        else:
            ctypes.windll.user32.MessageBoxW(0, '操作已取消', '右键快捷菜单设置(更换壁纸)', 0)
            pass
Beispiel #7
0
def insert_to_registery(window_handle):
    try:
        key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, SUBMODULE_KEY,
                                    0, win32con.KEY_ALL_ACCESS)
    except Exception:
        key = win32api.RegCreateKeyEx(win32con.HKEY_CURRENT_USER,
                                      SUBMODULE_KEY, win32con.KEY_ALL_ACCESS,
                                      None, winnt.REG_OPTION_NON_VOLATILE,
                                      None)[0]
    win32api.RegSetValueEx(key, str(ID_OF_INSTANCE), 0, win32con.REG_SZ,
                           str(window_handle))
Beispiel #8
0
def SetupRegistry():
    try:
        HKCU = win32api.RegOpenCurrentUser()
        key = win32api.RegCreateKeyEx(HKCU,
                                      config.Settings['RegistryLocation'],
                                      win32con.KEY_READ | win32con.KEY_WRITE)
    except Exception as er:
        print1("Fatal, cannot access Registry %s" %
               config.Settings['RegistryLocation'])
        sys.exit(0)
    print1("First Time Run, Setting Up Registry")
    return key[0]
Beispiel #9
0
def insert_to_registery(window_handle):
    id_of_instance = struct.unpack(">I", os.urandom(4))[0]
    try:
        key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,
                                    constants.SUBMODULE_KEY, 0,
                                    win32con.KEY_ALL_ACCESS)
    except Exception:
        key = win32api.RegCreateKeyEx(win32con.HKEY_CURRENT_USER,
                                      constants.SUBMODULE_KEY,
                                      win32con.KEY_ALL_ACCESS, None,
                                      winnt.REG_OPTION_NON_VOLATILE, None)[0]
    win32api.RegSetValueEx(key, str(id_of_instance), 0, win32con.REG_SZ,
                           str(window_handle))
    return id_of_instance
Beispiel #10
0
def set_pc_id():
    reg_root = win32con.HKEY_LOCAL_MACHINE
    reg_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AutoTax.exe"
    reg_flags = win32con.WRITE_OWNER | win32con.KEY_WOW64_64KEY | win32con.KEY_ALL_ACCESS

    try:
        #直接创建(若存在,则为获取)
        key, _ = win32api.RegCreateKeyEx(reg_root, reg_path, reg_flags)
        #设置项
        uid = uuid.uuid1()
        win32api.RegSetValueEx(key, "uid", 0, win32con.REG_SZ, str(uid))

        #关闭
        win32api.RegCloseKey(key)
        return uid
    except:
        return ''
Beispiel #11
0
def setScancodeMap(mapkey):
    try:

        try:
            key = win32api.RegOpenKeyEx(reg_root, reg_path, 0, reg_flags)
        except Exception as e:
            #log.log("try open failed in setScancodeMap")
            try:
                key = win32api.RegCreateKeyEx(reg_root, reg_path, reg_flags)
            except Exception as e:
                #log.log("try create failed in setScancodeMap")
                return False
            pass
        regstr = binascii.unhexlify(mapkey)
        win32api.RegSetValueEx(key, 'Scancode Map', 0, win32con.REG_BINARY,
                               regstr)
        win32api.RegCloseKey(key)
        return True
    except Exception as e:
        #log.log e
        return False
    pass
Beispiel #12
0
import win32api, win32con, win32transaction

keyname='Pywin32 test transacted registry functions'
subkeyname='test transacted subkey'
classname='Transacted Class'

trans=win32transaction.CreateTransaction(Description='test RegCreateKeyTransacted')
key, disp=win32api.RegCreateKeyEx(win32con.HKEY_CURRENT_USER, keyname,
    samDesired=win32con.KEY_ALL_ACCESS, Class=classname)
## clean up any existing keys
for subk in win32api.RegEnumKeyExW(key):
    win32api.RegDeleteKey(key, subk[0])

## reopen key in transacted mode
transacted_key=win32api.RegOpenKeyTransacted(Key=win32con.HKEY_CURRENT_USER, SubKey=keyname,
    Transaction=trans, samDesired=win32con.KEY_ALL_ACCESS)
subkey, disp=win32api.RegCreateKeyEx(transacted_key, subkeyname, Transaction=trans,
    samDesired=win32con.KEY_ALL_ACCESS, Class=classname)

## Newly created key should not be visible from non-transacted handle
subkeys=[s[0] for s in win32api.RegEnumKeyExW(key)]
assert subkeyname not in subkeys

transacted_subkeys=[s[0] for s in win32api.RegEnumKeyExW(transacted_key)]
assert subkeyname in transacted_subkeys

## Key should be visible to non-transacted handle after commit
win32transaction.CommitTransaction(trans)
subkeys=[s[0] for s in win32api.RegEnumKeyExW(key)]
assert subkeyname in subkeys
Beispiel #13
0
def set_value(
    hive,
    key,
    vname=None,
    vdata=None,
    vtype="REG_SZ",
    use_32bit_registry=False,
    volatile=False,
):
    """
    Sets a value in the registry. If ``vname`` is passed, it will be the value
    for that value name, otherwise it will be the default value for the
    specified key

    Args:

        hive (str):
            The name of the hive. Can be one of the following

                - HKEY_LOCAL_MACHINE or HKLM
                - HKEY_CURRENT_USER or HKCU
                - HKEY_USER or HKU
                - HKEY_CLASSES_ROOT or HKCR
                - HKEY_CURRENT_CONFIG or HKCC

        key (str):
            The key (looks like a path) to the value name.

        vname (str):
            The value name. These are the individual name/data pairs under the
            key. If not passed, the key (Default) value will be set.

        vdata (str, int, list, bytes):
            The value you'd like to set. If a value name (vname) is passed, this
            will be the data for that value name. If not, this will be the
            (Default) value for the key.

            The type of data this parameter expects is determined by the value
            type specified in ``vtype``. The correspondence is as follows:

                - REG_BINARY: Binary data (str in Py2, bytes in Py3)
                - REG_DWORD: int
                - REG_EXPAND_SZ: str
                - REG_MULTI_SZ: list of str
                - REG_QWORD: int
                - REG_SZ: str

                .. note::
                    When setting REG_BINARY, string data will be converted to
                    binary. You can pass base64 encoded using the ``binascii``
                    built-in module. Use ``binascii.b2a_base64('your data')``

            .. note::
                The type for the (Default) value is always REG_SZ and cannot be
                changed.

            .. note::
                This parameter is optional. If not passed, the Key will be
                created with no associated item/value pairs.

        vtype (str):
            The value type. The possible values of the vtype parameter are
            indicated above in the description of the vdata parameter.

        use_32bit_registry (bool):
            Sets the 32bit portion of the registry on 64bit installations. On
            32bit machines this is ignored.

        volatile (bool):
            When this parameter has a value of True, the registry key will be
            made volatile (i.e. it will not persist beyond a system reset or
            shutdown). This parameter only has an effect when a key is being
            created and at no other time.

    Returns:
        bool: True if successful, otherwise False

    Usage:

        This will set the version value to 2015.5.2 in the SOFTWARE\\Salt key in
        the HKEY_LOCAL_MACHINE hive

        .. code-block:: python

            import salt.utils.win_reg
            winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='version', vdata='2015.5.2')

    Usage:

        This function is strict about the type of vdata. For instance this
        example will fail because vtype has a value of REG_SZ and vdata has a
        type of int (as opposed to str as expected).

        .. code-block:: python

            import salt.utils.win_reg
            winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='str_data', vdata=1.2)

    Usage:

        In this next example vdata is properly quoted and should succeed.

        .. code-block:: python

            import salt.utils.win_reg
            winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='str_data', vdata='1.2')

    Usage:

        This is an example of using vtype REG_BINARY. Both ``set_value``
        commands will set the same value ``Salty Test``

        .. code-block:: python

            import salt.utils.win_reg
            winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='bin_data', vdata='Salty Test', vtype='REG_BINARY')

            import binascii
            bin_data = binascii.b2a_base64('Salty Test')
            winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='bin_data_encoded', vdata=bin_data, vtype='REG_BINARY')

    Usage:

        An example using vtype REG_MULTI_SZ is as follows:

        .. code-block:: python

            import salt.utils.win_reg
            winreg.set_value(hive='HKLM', key='SOFTWARE\\Salt', vname='list_data', vdata=['Salt', 'is', 'great'], vtype='REG_MULTI_SZ')
    """
    local_hive = _to_unicode(hive)
    local_key = _to_unicode(key)
    local_vname = _to_unicode(vname)
    local_vtype = _to_unicode(vtype)

    registry = Registry()
    try:
        hkey = registry.hkeys[local_hive]
    except KeyError:
        raise CommandExecutionError("Invalid Hive: {}".format(local_hive))
    vtype_value = registry.vtype[local_vtype]
    access_mask = registry.registry_32[
        use_32bit_registry] | win32con.KEY_ALL_ACCESS

    local_vdata = cast_vdata(vdata=vdata, vtype=local_vtype)

    if volatile:
        create_options = registry.opttype["REG_OPTION_VOLATILE"]
    else:
        create_options = registry.opttype["REG_OPTION_NON_VOLATILE"]

    handle = None
    try:
        handle, result = win32api.RegCreateKeyEx(hkey,
                                                 local_key,
                                                 access_mask,
                                                 Options=create_options)
        msg = ("Created new key: %s\\%s"
               if result == 1 else "Opened existing key: %s\\%s")
        log.debug(msg, local_hive, local_key)

        try:
            win32api.RegSetValueEx(handle, local_vname, 0, vtype_value,
                                   local_vdata)
            win32api.RegFlushKey(handle)
            broadcast_change()
            return True
        except TypeError as exc:
            log.exception('"vdata" does not match the expected data type.\n%s',
                          exc)
            return False
        except (SystemError, ValueError) as exc:
            log.exception("Encountered error setting registry value.\n%s", exc)
            return False

    except win32api.error as exc:
        log.exception(
            "Error creating/opening key: %s\\%s\n%s",
            local_hive,
            local_key,
            exc.winerror,
        )
        return False

    finally:
        if handle:
            win32api.RegCloseKey(handle)
Beispiel #14
0
)
ph = win32api.GetCurrentProcess()
th = win32security.OpenProcessToken(
    ph, win32con.TOKEN_READ | win32con.TOKEN_ADJUST_PRIVILEGES
)
adjusted_privs = win32security.AdjustTokenPrivileges(th, 0, required_privs)

try:
    sa = win32security.SECURITY_ATTRIBUTES()
    my_sid = win32security.GetTokenInformation(th, ntsecuritycon.TokenUser)[0]
    sa.SECURITY_DESCRIPTOR.SetSecurityDescriptorOwner(my_sid, 0)

    k, disp = win32api.RegCreateKeyEx(
        win32con.HKEY_CURRENT_USER,
        "Python test key",
        SecurityAttributes=sa,
        samDesired=win32con.KEY_ALL_ACCESS,
        Class="some class",
        Options=0,
    )
    win32api.RegSetValue(k, None, win32con.REG_SZ, "Default value for python test key")

    subk, disp = win32api.RegCreateKeyEx(
        k,
        "python test subkey",
        SecurityAttributes=sa,
        samDesired=win32con.KEY_ALL_ACCESS,
        Class="some other class",
        Options=0,
    )
    win32api.RegSetValue(subk, None, win32con.REG_SZ, "Default value for subkey")
Beispiel #15
0
 def create_key(self):
     """create and return a key"""
     key, _ = win32api.RegCreateKeyEx(self.root, self.path, REG_FLAGS)
     return key
Beispiel #16
0
os.remove(fname)

## enable backup and restore privs
required_privs = ((win32security.LookupPrivilegeValue('', ntsecuritycon.SE_BACKUP_NAME), win32con.SE_PRIVILEGE_ENABLED),
                  (win32security.LookupPrivilegeValue('', ntsecuritycon.SE_RESTORE_NAME), win32con.SE_PRIVILEGE_ENABLED)
                  )
ph = win32api.GetCurrentProcess()
th = win32security.OpenProcessToken(ph, win32con.TOKEN_READ | win32con.TOKEN_ADJUST_PRIVILEGES)
adjusted_privs = win32security.AdjustTokenPrivileges(th, 0, required_privs)

try:
    sa = win32security.SECURITY_ATTRIBUTES()
    my_sid = win32security.GetTokenInformation(th, ntsecuritycon.TokenUser)[0]
    sa.SECURITY_DESCRIPTOR.SetSecurityDescriptorOwner(my_sid, 0)

    k, disp = win32api.RegCreateKeyEx(win32con.HKEY_CURRENT_USER, 'Python test key', SecurityAttributes=sa,
                                      samDesired=win32con.KEY_ALL_ACCESS, Class='some class', Options=0)
    win32api.RegSetValue(k, None, win32con.REG_SZ, 'Default value for python test key')

    subk, disp = win32api.RegCreateKeyEx(k, 'python test subkey', SecurityAttributes=sa,
                                         samDesired=win32con.KEY_ALL_ACCESS, Class='some other class', Options=0)
    win32api.RegSetValue(subk, None, win32con.REG_SZ, 'Default value for subkey')

    win32api.RegSaveKeyEx(k, fname, Flags=winnt.REG_STANDARD_FORMAT, SecurityAttributes=sa)

    restored_key, disp = win32api.RegCreateKeyEx(win32con.HKEY_CURRENT_USER, 'Python test key(restored)',
                                                 SecurityAttributes=sa,
                                                 samDesired=win32con.KEY_ALL_ACCESS, Class='restored class', Options=0)
    win32api.RegRestoreKey(restored_key, fname)
finally:
    win32security.AdjustTokenPrivileges(th, 0, adjusted_privs)
Beispiel #17
0
 def create_key(self, path):
     key, _ = win32api.RegCreateKeyEx(self.root, path, self.flags)
     return key
Beispiel #18
0
reg_flags = win32con.WRITE_OWNER | win32con.KEY_WOW64_64KEY | win32con.KEY_ALL_ACCESS
try:
    key = win32api.RegOpenKeyEx(reg_root, reg_path, 0, reg_flags)
    for item in win32api.RegEnumKeyEx(key):
        print(item)
        i = 0
        while True:
            print(win32api.RegEnumValue(key, i))
            i += 1
except Exception as e:
    print(e)
    key = None
    pass
print(key)
keyFlag = False
if key is None:
    keyFlag = False
else:
    keyFlag = True
print(keyFlag)

try:
    # 直接创建(若存在,则为获取)
    key, _ = win32api.RegCreateKeyEx(reg_root, reg_path_parent, reg_flags)
    win32api.RegSetValueEx(key, '', 0, win32con.REG_SZ, '更换壁纸')
    key, _ = win32api.RegCreateKeyEx(reg_root, reg_path_children, reg_flags)
    win32api.RegSetValueEx(key, '', 0, win32con.REG_SZ, '我是猪儿子')
except Exception as e:
    print(e)
    key = None
print(key)
Beispiel #19
0
def set_value(hive,
              key,
              vname=None,
              vdata=None,
              vtype='REG_SZ',
              use_32bit_registry=False,
              volatile=False):
    '''
    Sets a registry value entry or the default value for a key.

    :param str hive: The name of the hive. Can be one of the following

        - HKEY_LOCAL_MACHINE or HKLM
        - HKEY_CURRENT_USER or HKCU
        - HKEY_USER or HKU

    :param str key: The key (looks like a path) to the value name.

    :param str vname: The value name. These are the individual name/data pairs
        under the key. If not passed, the key (Default) value will be set.

    :param object vdata: The value data to be set.
        What the type of this parameter
        should be is determined by the value of the vtype
        parameter. The correspondence
        is as follows:

        .. glossary::

           REG_BINARY
               binary data (i.e. str in python version < 3 and bytes in version >=3)
           REG_DWORD
               int
           REG_EXPAND_SZ
               str
           REG_MULTI_SZ
               list of objects of type str
           REG_SZ
               str

    :param str vtype: The value type.
        The possible values of the vtype parameter are indicated
        above in the description of the vdata parameter.

    :param bool use_32bit_registry: Sets the 32bit portion of the registry on
       64bit installations. On 32bit machines this is ignored.

    :param bool volatile: When this parameter has a value of True, the registry key will be
       made volatile (i.e. it will not persist beyond a system reset or shutdown).
       This parameter only has an effect when a key is being created and at no
       other time.

    :return: Returns True if successful, False if not
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2'

    This function is strict about the type of vdata. For instance the
    the next example will fail because vtype has a value of REG_SZ and vdata
    has a type of int (as opposed to str as expected).

    CLI Example:

    .. code-block:: bash

        salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
        vtype=REG_SZ vdata=0

    However, this next example where vdata is properly quoted should succeed.

    CLI Example:

    .. code-block:: bash

        salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
        vtype=REG_SZ vdata="'0'"

    An example of using vtype REG_BINARY is as follows:

    CLI Example:

    .. code-block:: bash

        salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
        vtype=REG_BINARY vdata='!!binary d2hhdCdzIHRoZSBwb2ludA=='

    An example of using vtype REG_LIST is as follows:

    CLI Example:

    .. code-block:: bash

        salt '*' reg.set_value HKEY_LOCAL_MACHINE 'SOFTWARE\\Salt' 'version' '2015.5.2' \\
        vtype=REG_LIST vdata='[a,b,c]'
    '''
    local_hive = _to_unicode(hive)
    local_key = _to_unicode(key)
    local_vname = _to_unicode(vname)
    local_vtype = _to_unicode(vtype)

    registry = Registry()
    hkey = registry.hkeys[local_hive]
    vtype_value = registry.vtype[local_vtype]
    access_mask = registry.registry_32[use_32bit_registry] | win32con.KEY_ALL_ACCESS

    # Check data type and cast to expected type
    # int will automatically become long on 64bit numbers
    # https://www.python.org/dev/peps/pep-0237/

    # String Types to Unicode
    if vtype_value in [1, 2]:
        local_vdata = _to_unicode(vdata)
    # Don't touch binary...
    elif vtype_value == 3:
        local_vdata = vdata
    # Make sure REG_MULTI_SZ is a list of strings
    elif vtype_value == 7:
        local_vdata = [_to_unicode(i) for i in vdata]
    # Everything else is int
    else:
        local_vdata = int(vdata)

    if volatile:
        create_options = registry.opttype['REG_OPTION_VOLATILE']
    else:
        create_options = registry.opttype['REG_OPTION_NON_VOLATILE']

    try:
        handle, _ = win32api.RegCreateKeyEx(hkey, local_key, access_mask,
                                   Options=create_options)
        win32api.RegSetValueEx(handle, local_vname, 0, vtype_value, local_vdata)
        win32api.RegFlushKey(handle)
        win32api.RegCloseKey(handle)
        broadcast_change()
        return True
    except (win32api.error, SystemError, ValueError, TypeError) as exc:  # pylint: disable=E0602
        log.error(exc, exc_info=True)
        return False
Beispiel #20
0
    dlg22 = app[bdt].Button2.click_input()
else:
    dlg22 = app[bdt].Button1.click_input()
time.sleep(2)
time.sleep(35)
dlg4 = app[bdt].Button1.click_input()
if len(bn) < 6:
    print('Готово')
else:
    reboot = app[bdt].Button1.click_input()
f = open('c:\\AutoDlInstall\\usr.txt', 'r')
user = f.read()
f.close()
hKey, flag = win32api.RegCreateKeyEx(
    win32con.HKEY_LOCAL_MACHINE,
    'SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Provider Filters\{06BEC7B3-65ED-4DAD-A5C5-48C81928D2B2}',
    win32con.KEY_ALL_ACCESS | win32con.KEY_WOW64_64KEY,
    Options=winnt.REG_OPTION_VOLATILE)
win32api.RegSetValueEx(hKey, 'Disabled', 0, winnt.REG_DWORD, 1)
hKey, flag = win32api.RegCreateKeyEx(
    win32con.HKEY_LOCAL_MACHINE,
    'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon',
    win32con.KEY_ALL_ACCESS | win32con.KEY_WOW64_64KEY,
    Options=winnt.REG_OPTION_VOLATILE)
win32api.RegSetValueEx(hKey, 'DefaultPassword', 0, winnt.REG_SZ, 'Password!')
hKey, flag = win32api.RegCreateKeyEx(
    win32con.HKEY_LOCAL_MACHINE,
    'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon',
    win32con.KEY_ALL_ACCESS | win32con.KEY_WOW64_64KEY,
    Options=winnt.REG_OPTION_VOLATILE)
win32api.RegSetValueEx(hKey, 'DefaultUserName', 0, winnt.REG_SZ, user)