Пример #1
0
def add_hello_context_menu():
    '''
    添加右键菜单,打印'Hello World'
    :return:
    '''
    # 菜单名称,如果含有中文,需要采用GBK编码格式,否则会出现乱码
    menu_name = 'Hello, 你好世界!'.decode('utf-8').encode('gbk')
    # 点击菜单所执行的命令
    menu_command = 'python d:/hello.py'

    # 打开名称为'HEKY_CLASSES_ROOT\\Directory\\Background\\shell'的注册表键,第一个参数为key,第二个参数为sub_key
    # 函数原型:OpenKey(key, sub_key, res = 0, sam = KEY_READ)
    # 注:路径分隔符依然要使用双斜杠'\\'
    key = reg.OpenKey(reg.HKEY_CLASSES_ROOT, r'Directory\\Background\\shell')

    # 为key创建一个名称为menu_name的sub_key,并设置sub_key的值为menu_name,数据类型为REG_SZ即字符串类型,后面跟的'(&H)'表示执行该sub_key的快捷键
    # 函数原型:SetValue(key, sub_key, type, value)
    reg.SetValue(key, menu_name, reg.REG_SZ, menu_name + '(&H)')

    # 打开刚刚创建的名为menu_name的子键
    sub_key = reg.OpenKey(key, menu_name)
    # 为sub_key添加名为'command'的子键,并设置其值为menu_command,数据类型为REG_SZ字符串类型
    reg.SetValue(sub_key, 'command', reg.REG_SZ, menu_command)

    # 关闭sub_key和key
    reg.CloseKey(sub_key)
    reg.CloseKey(key)
Пример #2
0
def addKeyValueToWindowsRegistry(key, value):
    ''' 保存键值对到windows注册表中 '''
    if cmp(os.name, 'nt') == 0:
        import _winreg

        regPrefixPath = _winreg.HKEY_CURRENT_USER
        regSubPath = u'Software\\SCS_client'

        try:
            reg = _winreg.OpenKey(regPrefixPath, regSubPath)
        except EnvironmentError:
            try:
                reg = _winreg.CreateKey(regPrefixPath, regSubPath)
            except:
                print "*** Unable to register!"
                return False
        try:
            if (_winreg.QueryValue(reg, key) != value):
                _winreg.DeleteKey(reg, key)
                _winreg.SetValue(reg, key, _winreg.REG_SZ, value)
        except Exception, e:
            _winreg.SetValue(reg, key, _winreg.REG_SZ, value)

        try:
            if reg: _winreg.CloseKey(reg)
        except Exception:
            pass

        return True
Пример #3
0
def add_open_with_chrome_menu():
    '''
    为文件添加右键菜单:用Chrome浏览器打开
    :return: None
    '''
    # 菜单名称,如果含有中文,需要采用GBK编码格式,否则会出现乱码
    menu_name = 'Open with chrome'
    # Chrome浏览器可执行文件所在的路径
    # 注:路径分隔符要使用双反斜杠'\\'
    exe_path = r'C:\\Users\\Administrator.PC-20170728DWIF\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe'

    # 打开名称为'HEKY_CLASSES_ROOT\*\shell'的注册表键,第一个参数为key,第二个参数为sub_key
    # 函数原型:OpenKey(key, sub_key, res = 0, sam = KEY_READ)
    # 注:路径分隔符依然要使用双斜杠'\\'
    key = reg.OpenKey(reg.HKEY_CLASSES_ROOT, r'*\\shell')
    # 为key创建一个名称为menu_name的sub_key,并设置sub_key的值为menu_name,数据类型为REG_SZ即字符串类型,后面跟的'(&C)'表示执行该sub_key的快捷键
    # 函数原型:SetValue(key, sub_key, type, value)
    reg.SetValue(key, menu_name, reg.REG_SZ, menu_name + '(&C)')

    # 打开刚刚创建的名为menu_name的sub_key
    sub_key = reg.OpenKey(key, menu_name)
    # 为sub_key添加名为'command'的子键,并设置其值为exe_path + ' %1',数据类型为REG_SZ字符串类型
    reg.SetValue(sub_key, 'command', reg.REG_SZ, exe_path + ' %1')

    # 关闭sub_key和key
    reg.CloseKey(sub_key)
    reg.CloseKey(key)
Пример #4
0
def add_context_menu(menu_name, command, reg_root_key_path, reg_key_path,
                     shortcut_key):
    '''
    封装的添加一个右键菜单的方法
    :param menu_name: 显示的菜单名称
    :param command: 菜单执行的命令
    :param reg_root_key_path: 注册表根键路径
    :param reg_key_path: 要添加到的注册表父键的路径(相对路径)
    :param shortcut_key: 菜单快捷键,如:'S'
    :return:
    '''
    # 打开名称父键
    key = reg.OpenKey(reg_root_key_path, reg_key_path)
    # 为key创建一个名称为menu_name的sub_key,并设置sub_key的值为menu_name加上快捷键,数据类型为REG_SZ字符串类型
    reg.SetValue(key, menu_name, reg.REG_SZ,
                 menu_name + '(&{0})'.format(shortcut_key))

    # 打开刚刚创建的名为menu_name的sub_key
    sub_key = reg.OpenKey(key, menu_name)
    # 为sub_key添加名为'command'的子键,并设置其值为command + ' "%v"',数据类型为REG_SZ字符串类型
    reg.SetValue(sub_key, 'command', reg.REG_SZ, command + ' "%v"')

    # 关闭sub_key和key
    reg.CloseKey(sub_key)
    reg.CloseKey(key)
Пример #5
0
    def registerWinTypeRcrd(self, desc, type, cmd):

        import _winreg

        try:
            software_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
                                           "Software", 0, _winreg.KEY_READ)
            classes_key = _winreg.OpenKey(software_key, "Classes", 0,
                                          _winreg.KEY_READ)

            fdesc_key = _winreg.CreateKey(classes_key, type)

            _winreg.OpenKey(classes_key, type, 0, _winreg.KEY_SET_VALUE)
            _winreg.SetValue(classes_key, type, _winreg.REG_SZ, desc)

            shell_key = _winreg.CreateKey(fdesc_key, "shell")
            open_key = _winreg.CreateKey(shell_key, "open")

            cmd_key = _winreg.CreateKey(open_key, "command")
            _winreg.OpenKey(open_key, "command", 0, _winreg.KEY_SET_VALUE)
            _winreg.SetValue(open_key, "command", _winreg.REG_SZ, cmd)

        except EnvironmentError:
            return False
        else:
            return True
def changeRemoteDesktopSetting(enableRDP=True):
    reg_key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
                              "System\\CurrentControlSet\\Control\\Terminal Server")
    if reg_key:
        if enableRDP:
            _winreg.SetValue(reg_key, "fDenyTSConnections", _winreg.REG_SZ, u'0')
        else:
            _winreg.SetValue(reg_key, "fDenyTSConnections", _winreg.REG_SZ, u'1')
Пример #7
0
def main():
    # Switch to our own dir.
    os.chdir(BASE_DIR)

    link = FindInPath('link.exe')
    mt = FindInPath('mt.exe')
    if not link or not mt:
        print(
            "Couldn't find link.exe or mt.exe in PATH. "
            "Must run from Administrator Visual Studio Command Prompt.")
        return 1

    link_backup = os.path.join(
        os.path.split(link)[0], 'link.exe.split_link.exe')

    # Don't re-backup link.exe, so only copy link.exe to backup if it's
    # not there already.
    if not os.path.exists(link_backup):
        try:
            print 'Saving original link.exe...'
            shutil.copyfile(link, link_backup)
        except IOError:
            print(("Wasn't able to back up %s to %s. "
                   "Not running with Administrator privileges?") %
                  (link, link_backup))
            return 1

    # Build our linker shim.
    print 'Building split_link.exe...'
    split_link_py = os.path.abspath('split_link.py')
    script_path = EscapeForCommandLineAndCString(split_link_py)
    python = EscapeForCommandLineAndCString(sys.executable)
    subprocess.check_call(
        'cl.exe /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE'
        ' /D_CRT_SECURE_NO_WARNINGS /EHsc split_link.cc'
        ' /DPYTHON_PATH="%s"'
        ' /DSPLIT_LINK_SCRIPT_PATH="%s"'
        ' /link shell32.lib shlwapi.lib /out:split_link.exe' %
        (python, script_path))

    # Copy shim into place.
    print 'Copying split_link.exe over link.exe...'
    try:
        shutil.copyfile('split_link.exe', link)
        _winreg.SetValue(_winreg.HKEY_CURRENT_USER,
                         'Software\\WhiteHat\\Aviator\\split_link_installed',
                         _winreg.REG_SZ, link_backup)
        _winreg.SetValue(_winreg.HKEY_CURRENT_USER,
                         'Software\\WhiteHat\\Aviator\\split_link_mt_path',
                         _winreg.REG_SZ, mt)
    except IOError:
        print(
            "Wasn't able to copy split_link.exe over %s. "
            "Not running with Administrator privileges?" % link)
        return 1

    return 0
Пример #8
0
def create_reg_key():
    try:
        reg = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, r'Software\MW')
        reg_mw = _winreg.CreateKey(reg, '3DPrinting')
        _winreg.SetValue(reg_mw, 'CorePath', 1, INST_FOLDER)
        _winreg.SetValue(reg_mw, 'ConfigFile', 1,
                         RHINO_FOLDER + LIB_FOLDER + CONFIG_FILE)
        # _winreg.CloseKey(_winreg.HKEY_LOCAL_MACHINE)
    except Exception as e:
        MWLOG.exception('REG KEY')
Пример #9
0
	def install_gedit_pecf_support (self):
		# If gedit installed, install pecf syntax
		os.chdir (path.join (eiffel_loop_home_dir, r'tool\toolkit'))

		edit_cmd = None
	
		gedit_dir = gedit_home_dir ()
		if gedit_dir:
			print gedit_dir
			for gtk_ver in range (2, 4):
				specs_dir = path.join (gedit_dir, r'share\gtksourceview-%s.0\language-specs' % gtk_ver)
				if path.exists (specs_dir):
					dir_util.copy_tree ('language-specs', specs_dir)
			gedit_exe_path = path.join (gedit_dir, r'bin\gedit.exe')
			if path.exists (gedit_exe_path):
				edit_cmd = '"%s"  "%%1"' % gedit_exe_path
		else:
			print 'It is recommended to install the gedit Text editor for editing .pecf files.'
			print 'Download and install from https://wiki.gnome.org/Apps/Gedit.'
			print "Then run 'setup.bat' again."
			r = raw_input ("Press <return> to continue")

		py_icon_path = path.join (python_home_dir, 'DLLs', 'py.ico')
		estudio_logo_path = r'"%ISE_EIFFEL%\contrib\examples\web\ewf\upload_image\htdocs\favicon.ico"'

		conversion_cmd = 'cmd /C el_toolkit -pyxis_to_xml -ask_user_to_quit -in "%1"'
		open_with_estudio_cmd = '"%s" "%%1"' % path.join (python_home_dir, "launch_estudio.bat")

		pecf_extension_cmds = {'open' : open_with_estudio_cmd, 'Convert To ECF' : conversion_cmd }
		pyx_extension_cmds = {'Convert To XML' : conversion_cmd }
		if edit_cmd:
			pecf_extension_cmds ['edit'] = edit_cmd
			pyx_extension_cmds ['open'] = edit_cmd
			pyx_extension_cmds ['edit'] = edit_cmd

		mime_types = [
			('.pecf', 'Pyxis.ECF.File', 'Pyxis Eiffel Configuration File', estudio_logo_path, pecf_extension_cmds),
			('.pyx', 'Pyxis.File', 'Pyxis Data File', py_icon_path, pyx_extension_cmds)
		]
		for extension_name, pyxis_key_name, description, icon_path, extension_cmds in mime_types:
			key = _winreg.CreateKeyEx (_winreg.HKEY_CLASSES_ROOT, extension_name, 0, _winreg.KEY_ALL_ACCESS)
			_winreg.SetValue (key, '', _winreg.REG_SZ, pyxis_key_name)

			pyxis_shell_path = path.join (pyxis_key_name, 'shell')
			for command_name, command in extension_cmds.iteritems():
				command_path = path.join (pyxis_shell_path, command_name, 'command')
				print 'Setting:', command_path, 'to', command
				key = _winreg.CreateKeyEx (_winreg.HKEY_CLASSES_ROOT, command_path, 0, _winreg.KEY_ALL_ACCESS)
				_winreg.SetValue (key, '', _winreg.REG_SZ, command)

			key = _winreg.CreateKeyEx (_winreg.HKEY_CLASSES_ROOT, pyxis_key_name, 0, _winreg.KEY_ALL_ACCESS)
			_winreg.SetValue (key, '', _winreg.REG_SZ, description)

			key = _winreg.CreateKeyEx (_winreg.HKEY_CLASSES_ROOT, path.join (pyxis_key_name, 'DefaultIcon'), 0, _winreg.KEY_ALL_ACCESS)
			_winreg.SetValue (key, '', _winreg.REG_SZ, icon_path)
Пример #10
0
def register(label, action, filetype='Python.File', suffix='"%1"'):
    """Register action with a label in the windows explorer context menu.

    :param label: label describing the action
    :type label: str
    :param action: command line for the action
    :type action: str
    :param filetype: file type in the Windows registry
    :type filetype: str
    :param suffix: suffix parameters for the action (command line)
    :type suffix: str
    :returns: ``True`` if successfull, ``False`` otherwise
    :rtype: bool
    """
    try:
        k = '%s\\shell\\%s' % (filetype, label)
        key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, k)
    except:
        pass
    try:
        command = '%s %s' % (action, suffix)
        _winreg.SetValue(key, "command", _winreg.REG_SZ, command)
        return key
    except:
        return False
Пример #11
0
def insert_natlink_python_path_registry(python_version):
    """
        Given a Python version string, e.g. '2.5', sets the value of the registry key

            HKEY_LOCAL_MACHINE\Software\Python\PythonCore\XXX\PythonPath\NatLink

        to

            "%s;%s" % (natlink_macro_system_path(), natlink_misc_scripts_path())

        creating the key if it does not already exist.            

        >>> delete_natlink_python_path_registry('2.5')
        True
        >>> get_natlink_python_path_registry('2.5') is None
        True
        >>> insert_natlink_python_path_registry('2.5')
        >>> get_natlink_python_path_registry('2.5')
        u'C:\\\\Program Files\\\\NatLink\\\\MacroSystem;C:\\\\Program Files\\\\NatLink\\\\MiscScripts'
    """
    if get_natlink_python_path(python_version) is None:
        registry.SetValue(registry.HKEY_LOCAL_MACHINE,
                          r'Software\Python\PythonCore\%s\PythonPath\NatLink'
                              % python_version,
                          registry.REG_SZ,
                          "%s;%s" % (natlink_macro_system_path(), natlink_misc_scripts_path()))
Пример #12
0
    def createKey(path, default=None, start=None):
        """
        Creates a given registry key, possibly setting it's (default) value

        Path is a /-separated path

        Currenly only the top-levels HKCR and HKLM are supported.

        Returns the newly-created key
        """
        path = path.split("/")
        while path[0] == "":
            path = path[1:]
        if start == None:
            if path[0] == "HKCR" or path[0] == "HKEY_CLASSES_ROOT":
                reg = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, None)
            elif path[0] == "HKLM" or path[0] == "HKEY_LOCAL_MACHINE":
                reg = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, None)
            else:
                print "Bad registry path: " + path
        else:
            reg = start
        for i in range(1, len(path)):
            parent = reg
            reg = _winreg.CreateKey(parent, path[i])
        if default != None:
            _winreg.SetValue(parent, path[-1], _winreg.REG_SZ, default)
        return reg
Пример #13
0
def register(root, key, subkey, value, regtype=winreg.REG_SZ):
    reg = winreg.CreateKeyEx(root, key, 0,
                             winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_32KEY)
    if subkey == '@':
        winreg.SetValue(reg, None, regtype, value)
    else:
        winreg.SetValueEx(reg, subkey, 0, regtype, value)
    winreg.CloseKey(reg)

    reg = winreg.CreateKeyEx(root, key, 0,
                             winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY)
    if subkey == '@':
        winreg.SetValue(reg, None, regtype, value)
    else:
        winreg.SetValueEx(reg, subkey, 0, regtype, value)
    winreg.CloseKey(reg)
Пример #14
0
    def _check_reg(self, sub_key):
        # see comments in check_httpd(), above, for why this routine exists and what it's doing.
        try:
            # Note that we HKCR is a union of HKLM and HKCR (with the latter
            # overriding the former), so reading from HKCR ensures that we get
            # the value if it is set in either place. See als comments below.
            hkey = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, sub_key)
            args = _winreg.QueryValue(hkey, '').split()
            _winreg.CloseKey(hkey)

            # In order to keep multiple checkouts from stepping on each other, we simply check that an
            # existing entry points to a valid path and has the right command line.
            if len(args) == 2 and self._filesystem.exists(args[0]) and args[0].endswith('perl.exe') and args[1] == '-wT':
                return True
        except WindowsError as error:  # WindowsError is not defined on non-Windows platforms - pylint: disable=undefined-variable
            if error.errno != errno.ENOENT:
                raise
            # The key simply probably doesn't exist.

        # Note that we write to HKCU so that we don't need privileged access
        # to the registry, and that will get reflected in HKCR when it is read, above.
        cmdline = self._path_from_chromium_base(
            'third_party', 'perl', 'perl', 'bin', 'perl.exe') + ' -wT'
        hkey = _winreg.CreateKeyEx(_winreg.HKEY_CURRENT_USER, 'Software\\Classes\\' + sub_key, 0, _winreg.KEY_WRITE)
        _winreg.SetValue(hkey, '', _winreg.REG_SZ, cmdline)
        _winreg.CloseKey(hkey)
        return True
Пример #15
0
def create_registery_entry(path):
	print "Creation dans le registre"
	register_name = _winreg.HKEY_CLASSES_ROOT
	register_path = "*\\shell\\"
	new_register_name = "DownloadSubtitle"
	try:
		# Create main register
		reg = _winreg.CreateKey(register_name, register_path)
		_winreg.SetValue(reg, "DownloadSubtitle", _winreg.REG_SZ, "Download subtitle")
		_winreg.CloseKey(reg)
		# Create sub register
		reg = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, register_path + new_register_name)
		_winreg.SetValue(reg, "command", _winreg.REG_SZ, "\""+ path +"\main.exe\" \"%1\"")
		_winreg.CloseKey(reg)
	except:
		print "registre"
Пример #16
0
 def register(self):
     key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, r'Folder\shell')
     newKey = _winreg.CreateKeyEx(key, 'cmdPrompt', 0, KEY_ALL_ACCESS)
     subKey = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, r'Folder\shell\cmdPrompt')
     _winreg.SetValue(subKey, 'command', _winreg.REG_SZ, 'C:\Windows\system32\cmd.exe cd' + ' "%1"')
     _winreg.CloseKey(key)
     _winreg.CloseKey(subKey)
def set_config_value(key, value):
    try:
        cfg_root_key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE,
                                         "SOFTWARE\\BitSquid\\BSIExporter\\")
        _winreg.SetValue(cfg_root_key, key, _winreg.REG_SZ, value)
        cfg_root_key.Close()
    except Exception, e:
        pass
Пример #18
0
 def set_value(self, key, subkey, value):
     """ Set a value in a custom subkey
     """
     try:
         return winreg.SetValue(key, subkey, winreg.REG_SZ, value)
     except WindowsError as error:
         print "Error al crear un valor"
         self.no_restore = True
Пример #19
0
def install(args):
    import os, sys
    import pythoncom
    from os.path import join, split, abspath
    from win32com.shell import shell, shellcon

    assert (sys.platform == "win32")

    windows_exec = os.path.join(split(sys.executable)[0], "pythonw.exe")

    shortcut = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None,
                                          pythoncom.CLSCTX_INPROC_SERVER,
                                          shell.IID_IShellLink)
    shortcut.SetPath(windows_exec)
    shortcut.SetDescription("Start Emacs")
    shortcut.SetIconLocation(join(emacs_bin, "runemacs.exe"), 0)
    shortcut.SetArguments('"{}" start'.format(abspath(__file__)))

    start_menu = shell.SHGetFolderPath(0, shellcon.CSIDL_STARTMENU, 0, 0)
    # desktop_path = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
    persist_file = shortcut.QueryInterface(pythoncom.IID_IPersistFile)
    persist_file.Save(os.path.join(start_menu, "Programs", "Emacs.lnk"), 0)

    import _winreg
    from os.path import abspath, join, split

    windows_exec = join(split(sys.executable)[0], "pythonw.exe")
    cmd = '"{}" "{}" edit "%l"'.format(windows_exec, abspath(__file__))

    try:
        key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT,
                              "*\Shell\Open in emacs")
    except WindowsError:
        key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
                                "*\Shell\Open in emacs")

    _winreg.SetValue(key, "Command", _winreg.REG_SZ, cmd)

    try:
        key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT,
                              "Directory\Shell\Open in emacs")
    except WindowsError:
        key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
                                "Directory\Shell\Open in emacs")

    _winreg.SetValue(key, "Command", _winreg.REG_SZ, cmd)
Пример #20
0
def _create_registry_key_helper(regval):
    reg = W.ConnectRegistry(None, W.HKEY_CURRENT_USER)
    p = W.OpenKey(reg, r'Software\Classes', 0, W.KEY_SET_VALUE)
    p2 = W.CreateKey(p, 'Python.File\shell\Edit with IdleX\command')
    W.SetValue(p2, '', W.REG_SZ, regval)
    W.CloseKey(p2)
    W.CloseKey(p)
    W.CloseKey(reg)
Пример #21
0
 def set_value(self, key, subkey, value):
     """ Set a value in a custom subkey
     """
     try:
         return winreg.SetValue(key, subkey, winreg.REG_SZ, value)
     except:
         self.no_restore = True
         return None
Пример #22
0
 def set_py_runas_admin(self):
     value = '\"C:\\Python27\\python.exe\" \"%1\" %*'      
     try:
         with reg.CreateKey(CLASSES_ROOT, self.keys.py_runas_admin) as key:
             reg.SetValue(key, 'command', reg.REG_SZ, value)
     except:
         warn('Failed to set key for running python file type as admin.')
     py_runas_admin = self.keys.py_runas_admin
     return values(py_runas_admin, HKCR=True)[0]['Values'][''] == value
Пример #23
0
def setitemdefaultvalue(regpath, key_type, value):
    key = regpath.split('\\')[len(regpath.split('\\')) - 1]
    keytype = key_type.upper()
    root = regpath.split('\\')[0].upper()
    path = '\\'.join(regpath.split('\\')[1:len(regpath.split('\\')) - 1])
    keyHandle = _winreg.CreateKey(regDict[root], path)
    ret = _winreg.SetValue(
        keyHandle, key, regDict[keytype],
        value)  ##_winreg.SetValue(key, sub_key, type, value),type可以用数字的
Пример #24
0
def _register(extension,
              icon=None,
              verbs={},
              description=None,
              shortcutOverlay=False,
              shellExtensions={}):
    """
	extension - file extension to register (starting with ".")
	icon - path to the icon for this extension
	verbs - a dict of {name:commandline} for example {'open':'notepad.exe "%1"'}
	description - a longer text description
	shortcutOverlay - tell the shell to draw the "shortcut" arrow over the icon
	shellExtensions - {type:classid} register code to handle things like thumbnails, dragdrop, etc
		see: https://msdn.microsoft.com/en-us/library/windows/desktop/cc144067(v=vs.85).aspx
	"""
    key = winreg.CreateKeyEx(winreg.HKEY_CLASSES_ROOT, extension)
    if description:
        winreg.SetValue(winreg.HKEY_CLASSES_ROOT, extension, winreg.REG_SZ,
                        description)
    if icon:
        winreg.SetValue(key, 'DefaultIcon', winreg.REG_SZ, icon)
    if shortcutOverlay:
        winreg.SetValueEx(key, 'IsShortcut', 0, winreg.REG_SZ, '')
    else:
        try:
            winreg.DeleteKey(key, 'IsShortcut')
        except Exception:
            pass
    if verbs:
        subkey = winreg.CreateKeyEx(key, 'Shell')
        for name, commandline in verbs.items():
            shortname = name.replace(' ', '')
            verbKey = winreg.CreateKeyEx(subkey, shortname)
            if shortname != name:
                winreg.SetValue(verbKey, shortname, winreg.REG_SZ, name)
            winreg.CreateKeyEx(verbKey, 'command')
            winreg.SetValue(verbKey, 'command', winreg.REG_SZ, commandline)
    if shellExtensions:
        subkey = winreg.CreateKeyEx(key, 'ShellEx')
        for typename, clsid in shellExtensions.items():
            winreg.CreateKeyEx(subkey, typename)
            winreg.SetValue(subkey, typename, winreg.REG_SZ, clsid)
Пример #25
0
def install():
    if sys.platform == 'win32':
        try:
            import _winreg
        except ImportError:
            pass
        else:
            print 'Writing "App Paths" registry entry for %s' % scons_bat_path
            _winreg.SetValue(_winreg.HKEY_LOCAL_MACHINE, app_paths_key,
                             _winreg.REG_SZ, scons_bat_path)
            print 'Done.'
Пример #26
0
def CreateContextMenuEntry(AL_path, language):
    cmdline = '%s "%%1" /L%s' % (AL_path, language)
    try:
        shellkey = wreg.OpenKey(wreg.HKEY_CLASSES_ROOT, r"exefile\shell", 0,
                                wreg.KEY_ALL_ACCESS)
    except WindowsError:
        print "[!] Error: Could not open key. Ensure script is ran as Administrator"
        return False
    appkey = wreg.CreateKey(shellkey, "Execute with AppLocale")
    cmdkey = wreg.CreateKey(appkey, "command")
    wreg.SetValue(cmdkey, "", wreg.REG_SZ, cmdline)
    return True
Пример #27
0
def register(label, action, filetype='Python.File', suffix='"%1"'):
    try:
        k = '%s\\shell\\%s' % (filetype, label)
        key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, k)
    except:
        pass
    try:
        command = '%s %s' % (action, suffix)
        _winreg.SetValue(key, "command", _winreg.REG_SZ, command)
        return key
    except:
        return False
Пример #28
0
    def set_subkey(self, subkey_name, value):
        """
            Set subkey (Default) value in registry

            Example:
            >>> r.set_subkey('test', 'test_str')
            >>> r.get_subkey('test')
            'test_str'
        """
        if not self.can_write:
            raise WindowsError, "Registry opened with read-only rights %s (0x%x)" % ( WindowsRegistry.RIGHTSDICT[self.right], self.right )
        wreg.SetValue(self.key, subkey_name, wreg.REG_SZ, str(value))
Пример #29
0
def make_service(servicename, commandline):
    subprocess.check_call([instsrv, servicename, srvany])

    # if we get this far the registry entry will be created. We now need
    # to tell it what to actually run

    service_key_name = r"SYSTEM\CurrentControlSet\Services\\" + servicename

    with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, service_key_name) as reg:
        with  _winreg.CreateKey(reg, "Parameters") as k:
            _winreg.SetValue(
                k, "Application", _winreg.REG_SZ,
                commandline)
Пример #30
0
 def fix_registry(python_ver):
     """Update install path on windows registry so PyQt installation installs at the correct
     location.
     python_ver must be "34", "27", etc.
     """
     import _winreg as winreg
     python_dir = r'C:\Python%s' % python_ver
     print("Fixing registry %s..." % python_ver)
     assert os.path.isdir(python_dir)
     registry_key = r'Software\Python\PythonCore\%s.%s' % (python_ver[0],
                                                           python_ver[1])
     with winreg.OpenKey(winreg.HKEY_CURRENT_USER, registry_key, 0,
                         winreg.KEY_WRITE) as key:
         winreg.SetValue(key, 'InstallPath', winreg.REG_SZ, python_dir)