Esempio n. 1
0
def RegisterCoreDLL(coredllName=None):
    """Registers the core DLL in the registry.

        If no params are passed, the name of the Python DLL used in 
        the current process is used and registered.
	"""
    if coredllName is None:
        coredllName = win32api.GetModuleFileName(sys.dllhandle)
        # must exist!
    else:
        try:
            os.stat(coredllName)
        except os.error:
            print("Warning: Registering non-existant core DLL %s" %
                  coredllName)

    hKey = win32api.RegCreateKey(GetRootKey(), BuildDefaultPythonKey())
    try:
        win32api.RegSetValue(hKey, "Dll", win32con.REG_SZ, coredllName)
    finally:
        win32api.RegCloseKey(hKey)
    # Lastly, setup the current version to point to me.
    win32api.RegSetValue(GetRootKey(),
                         "Software\\Python\\PythonCore\\CurrentVersion",
                         win32con.REG_SZ, sys.winver)
Esempio n. 2
0
def _register(cls):
    """Register an inproc com server in HKEY_CURRENT_USER.

    This may be used as a replacement for win32com.server.register.UseCommandLine
    to register the server into the HKEY_CURRENT_USER area of the registry
    instead of HKEY_LOCAL_MACHINE.
    """
    clsid_path = "Software\\Classes\\CLSID\\" + cls._reg_clsid_
    progid_path = "Software\\Classes\\" + cls._reg_progid_
    spec = cls.__module__ + "." + cls.__name__

    # register the class information
    win32api.RegSetValue(win32con.HKEY_CURRENT_USER, clsid_path,
                         win32con.REG_SZ, cls._reg_desc_)
    win32api.RegSetValue(win32con.HKEY_CURRENT_USER, clsid_path + "\\ProgID",
                         win32con.REG_SZ, cls._reg_progid_)
    win32api.RegSetValue(win32con.HKEY_CURRENT_USER,
                         clsid_path + "\\PythonCOM", win32con.REG_SZ, spec)
    hkey = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER,
                                 clsid_path + "\\InprocServer32")
    win32api.RegSetValueEx(hkey, None, None, win32con.REG_SZ,
                           pythoncom.__file__)
    win32api.RegSetValueEx(hkey, "ThreadingModel", None, win32con.REG_SZ,
                           "Both")

    # and add the progid
    win32api.RegSetValue(win32con.HKEY_CURRENT_USER, progid_path,
                         win32con.REG_SZ, cls._reg_desc_)
    win32api.RegSetValue(win32con.HKEY_CURRENT_USER, progid_path + "\\CLSID",
                         win32con.REG_SZ, cls._reg_clsid_)
Esempio n. 3
0
def RegisterDDECommand(shellCommand, ddeApp, ddeTopic, ddeCommand):
    base = "%s\\Shell" % RegistryIDPyFile
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + "\\%s\\ddeexec" % (shellCommand), win32con.REG_SZ,
                         ddeCommand)
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + "\\%s\\ddeexec\\Application" % (shellCommand),
                         win32con.REG_SZ, ddeApp)
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + "\\%s\\ddeexec\\Topic" % (shellCommand), win32con.REG_SZ,
                         ddeTopic)
Esempio n. 4
0
def RegisterShellCommand(shellCommand, exeCommand, shellUserCommand = None):
	# Last param for "Open" - for a .py file to be executed by the command line
	# or shell execute (eg, just entering "foo.py"), the Command must be "Open",
	# but you may associate a different name for the right-click menu.
	# In our case, normally we have "Open=Run"
	base = "%s\\Shell" % RegistryIDPyFile
	if shellUserCommand:
		win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT , base + "\\%s" % (shellCommand), win32con.REG_SZ, shellUserCommand)

	win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT , base + "\\%s\\Command" % (shellCommand), win32con.REG_SZ, exeCommand)
Esempio n. 5
0
def RegisterNamedPath(name, path):
    """Register a named path - ie, a named PythonPath entry.
    """
    keyStr = BuildDefaultPythonKey() + "\\PythonPath"
    if name:
        keyStr = keyStr + "\\" + name
    win32api.RegSetValue(GetRootKey(), keyStr, win32con.REG_SZ, path)
Esempio n. 6
0
def RegisterHelpFile(helpFile, helpPath, helpDesc=None, bCheckFile=1):
    """Register a help file in the registry.

      Note that this used to support writing to the Windows Help
      key, however this is no longer done, as it seems to be incompatible.

    helpFile -- the base name of the help file.
    helpPath -- the path to the help file
    helpDesc -- A description for the help file.  If None, the helpFile param is used.
    bCheckFile -- A flag indicating if the file existence should be checked.
    """
    if helpDesc is None:
        helpDesc = helpFile
    fullHelpFile = os.path.join(helpPath, helpFile)
    try:
        if bCheckFile:
            os.stat(fullHelpFile)
    except os.error:
        raise ValueError("Help file does not exist")
    # Now register with Python itself.
    win32api.RegSetValue(
        GetRootKey(),
        BuildDefaultPythonKey() + "\\Help\\%s" % helpDesc,
        win32con.REG_SZ,
        fullHelpFile,
    )
Esempio n. 7
0
def _set_string(path, value, base=win32con.HKEY_CLASSES_ROOT):
  "Set a string value in the registry."

  win32api.RegSetValue(base,
                       path,
                       win32con.REG_SZ,
                       value)
Esempio n. 8
0
def InstallPythonClassString(pythonClassString, serviceName):
    # Now setup our Python specific entries.
    if pythonClassString:
        key = win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Services\\%s\\PythonClass" % serviceName)
        try:
            win32api.RegSetValue(key, None, win32con.REG_SZ, pythonClassString);
        finally:
            win32api.RegCloseKey(key)
Esempio n. 9
0
 def change():
     hkey = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER,
                                  self.key_name)
     try:
         win32api.RegSetValue(hkey, None, win32con.REG_SZ, "foo")
     finally:
         win32api.RegDeleteKey(win32con.HKEY_CURRENT_USER,
                               self.key_name)
Esempio n. 10
0
def SetRegistryDefaultValue(subKey, value, rootkey = None):
	"""A helper to set the default value for a key in the registry
        """
	if rootkey is None: rootkey = GetRootKey()
	if type(value)==str:
		typeId = win32con.REG_SZ
	elif type(value)==int:
		typeId = win32con.REG_DWORD
	else:
		raise TypeError("Value must be string or integer - was passed " + repr(value))

	win32api.RegSetValue(rootkey, subKey, typeId ,value)
Esempio n. 11
0
def RegisterModule(modName, modPath):
    """Register an explicit module in the registry.  This forces the Python import
           mechanism to locate this module directly, without a sys.path search.  Thus
           a registered module need not appear in sys.path at all.

	   modName -- The name of the module, as used by import.
	   modPath -- The full path and file name of the module.
	"""
    try:
        import os
        os.stat(modPath)
    except os.error:
        print "Warning: Registering non-existant module %s" % modPath
    win32api.RegSetValue(GetRootKey(),
                         BuildDefaultPythonKey() + "\\Modules\\%s" % modName,
                         win32con.REG_SZ, modPath)
Esempio n. 12
0
def SetupCore(searchPaths):
    """Setup the core Python information in the registry.

    This function makes no assumptions about the current state of sys.path.

    After this function has completed, you should have access to the standard
    Python library, and the standard Win32 extensions
    """

    import sys

    for path in searchPaths:
        sys.path.append(path)

    import os
    import regutil, win32api, win32con

    installPath, corePaths = LocatePythonCore(searchPaths)
    # Register the core Pythonpath.
    print(corePaths)
    regutil.RegisterNamedPath(None, ";".join(corePaths))

    # Register the install path.
    hKey = win32api.RegCreateKey(regutil.GetRootKey(),
                                 regutil.BuildDefaultPythonKey())
    try:
        # Core Paths.
        win32api.RegSetValue(hKey, "InstallPath", win32con.REG_SZ, installPath)
    finally:
        win32api.RegCloseKey(hKey)

    # Register the win32 core paths.
    win32paths = (
        os.path.abspath(os.path.split(win32api.__file__)[0]) + ";" +
        os.path.abspath(
            os.path.split(LocateFileName("win32con.py;win32con.pyc",
                                         sys.path))[0]))

    # Python has builtin support for finding a "DLLs" directory, but
    # not a PCBuild.  Having it in the core paths means it is ignored when
    # an EXE not in the Python dir is hosting us - so we add it as a named
    # value
    check = os.path.join(sys.prefix, "PCBuild")
    if "64 bit" in sys.version:
        check = os.path.join(check, "amd64")
    if os.path.isdir(check):
        regutil.RegisterNamedPath("PCBuild", check)
Esempio n. 13
0
def RegisterPythonExe(exeFullPath, exeAlias = None, exeAppPath = None):
	"""Register a .exe file that uses Python.

	   Registers the .exe with the OS.  This allows the specified .exe to
	   be run from the command-line or start button without using the full path,
	   and also to setup application specific path (ie, os.environ['PATH']).

	   Currently the exeAppPath is not supported, so this function is general
	   purpose, and not specific to Python at all.  Later, exeAppPath may provide
	   a reasonable default that is used.

	   exeFullPath -- The full path to the .exe
	   exeAlias = None -- An alias for the exe - if none, the base portion
	             of the filename is used.
	   exeAppPath -- Not supported.
	"""
	# Note - Dont work on win32s (but we dont care anymore!)
	if exeAppPath:
		raise error("Do not support exeAppPath argument currently")
	if exeAlias is None:
		exeAlias = os.path.basename(exeFullPath)
	win32api.RegSetValue(GetRootKey(), GetAppPathsKey() + "\\" + exeAlias, win32con.REG_SZ, exeFullPath)
Esempio n. 14
0
def 系统_建立关联文件(后缀,程序路径,图标=None):
    '后缀:.pyec,程序路径:完整的路径'
    程序名 = os.path.splitext(程序路径)[0]
    图标 = 图标 if 图标 else 程序路径
    # 创建
    key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, '', 0, win32con.KEY_READ)
    win32api.RegCreateKey(key, 后缀)
    win32api.RegCreateKey(key, 程序名 + '\\BrowserFlags')
    win32api.RegCreateKey(key, 程序名 + '\\EditFlags')
    win32api.RegCreateKey(key, 程序名 + '\\DefaultIcon\\')
    win32api.RegCreateKey(key, 程序名 + '\\shell\\')
    win32api.RegCreateKey(key, 程序名 + '\\shell\\open\\command\\')
    win32api.RegCloseKey(key)
    # 写入默认值
    key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, '', 0, win32con.KEY_READ)
    win32api.RegSetValue(key, '.pyec', win32con.REG_SZ, 程序名)
    win32api.RegSetValue(key, 程序名 + '\\BrowserFlags', win32con.REG_SZ, "8")
    win32api.RegSetValue(key, 程序名 + '\\EditFlags', win32con.REG_SZ, "0")
    win32api.RegSetValue(key, 程序名 + '\\DefaultIcon\\', win32con.REG_SZ,'"{}"'.format(图标))
    win32api.RegSetValue(key, 程序名 + '\\shell\\', win32con.REG_SZ, 'open')
    win32api.RegSetValue(key, 程序名 + '\\shell\\open\\command\\', win32con.REG_SZ,r'{} "%1"'.format(程序路径))
    win32api.RegCloseKey(key)
    return True
Esempio n. 15
0
    def WriteCdgKey():

        key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT, '\\*\\shell\\')
        subkey = win32api.RegCreateKey(key, "CDG_Put_In")
        win32api.RegSetValue(subkey, '', win32con.REG_SZ, 'CDG_Put_In')
        subkey2 = win32api.RegCreateKey(subkey, r'command')
        win32api.RegSetValue(
            subkey2, '', win32con.REG_SZ, '\"%s\" \"%s\" -f \"%%1\"' %
            (WindowsUtil.FindPythonExe(),
             os.path.join(os.getcwd(), "Base/CmdHelp.py")))
        win32api.CloseHandle(subkey2)
        win32api.CloseHandle(subkey)

        key = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT,
                                  '\\Directory\\Background\\shell\\')

        subkey = win32api.RegCreateKey(key, "CDG_Clear_Out")
        win32api.RegSetValue(subkey, '', win32con.REG_SZ, 'CDG_Clear_Out')
        subkey2 = win32api.RegCreateKey(subkey, r'command')
        win32api.RegSetValue(
            subkey2, '', win32con.REG_SZ, '\"%s\" \"%s\" -c' %
            (WindowsUtil.FindPythonExe(),
             os.path.join(os.getcwd(), "Base/CmdHelp.py")))
        win32api.CloseHandle(subkey2)
        win32api.CloseHandle(subkey)

        subkey = win32api.RegCreateKey(key, "CDG_Copy_To")
        win32api.RegSetValue(subkey, '', win32con.REG_SZ, 'CDG_Copy_To')
        subkey2 = win32api.RegCreateKey(subkey, r'command')
        win32api.RegSetValue(
            subkey2, '', win32con.REG_SZ, '\"%s\" \"%s\" -t \"%%V\"' %
            (WindowsUtil.FindPythonExe(),
             os.path.join(os.getcwd(), "Base/CmdHelp.py")))
        win32api.CloseHandle(subkey2)
        win32api.CloseHandle(subkey)
        win32api.CloseHandle(key)
Esempio n. 16
0
 def write(path, value):
     win32api.RegSetValue(win32con.HKEY_CURRENT_USER, path, win32con.REG_SZ,
                          value)
Esempio n. 17
0
## 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)
Esempio n. 18
0
import win32api
import win32con
from win32com.server import register
import iconOverlay

key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, r'Software\Dachengyun')
winreg.SetValueEx(key, 'path', 0, winreg.REG_SZ, os.getcwd())
winreg.SetValueEx(key, 'dbPath', 0, winreg.REG_SZ,
                  os.path.join(os.getcwd(), 'data.db'))
winreg.SetValueEx(key, 'iconPath', 0, winreg.REG_SZ,
                  os.path.join(os.getcwd(), 'icon'))
winreg.SetValueEx(key, 'serverPath', 0, winreg.REG_SZ,
                  r'http://127.0.0.1:8000/')
winreg.SetValueEx(key, 'fileMaxSize', 0, winreg.REG_SZ, '104857600')
winreg.FlushKey(key)
key.Close()

register.UseCommandLine(iconOverlay.IconOverlayOk)
win32api.RegSetValue(
    win32api.RegCreateKey(iconOverlay.IconOverlayOk._reg_remove_keys_[0][1],
                          iconOverlay.IconOverlayOk._reg_remove_keys_[0][0]),
    None, win32con.REG_SZ, iconOverlay.IconOverlayOk._reg_clsid_)

register.UseCommandLine(iconOverlay.IconOverlaySync)
win32api.RegSetValue(
    win32api.RegCreateKey(iconOverlay.IconOverlaySync._reg_remove_keys_[0][1],
                          iconOverlay.IconOverlaySync._reg_remove_keys_[0][0]),
    None, win32con.REG_SZ, iconOverlay.IconOverlaySync._reg_clsid_)

os.system('taskkill /f /im explorer.exe & start explorer.exe')
Esempio n. 19
0
except win32api.error, msg:
    corehandle = win32api.RegCreateKey(pythonhandle, corekey)
path = []
pwd = nt.getcwd()
for i in ["Bin",
	  "Lib",
	  "Lib\\win",
	  "Lib\\tkinter",
	  "Lib\\test",
	  "Lib\\dos_8x3"]:
    i = pwd + "\\" + i
    path.append(i)
sys.path[1:] = path
pathvalue = strop.join(path, ";")
#print "Setting PythonPath to", pathvalue
win32api.RegSetValue(corehandle, "PythonPath", win32con.REG_SZ, pathvalue)
win32api.RegCloseKey(corehandle)
#listtree(pythonhandle)
win32api.RegCloseKey(pythonhandle)

print "Registering uninstaller..."
pwd = nt.getcwd()
uninstaller = '"%s\\uninstall.bat" "%s"' % (pwd, pwd)
uninstallkey = \
 "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Python"+sys.winver
try:
    uihandle = win32api.RegOpenKey(roothandle, uninstallkey)
except win32api.error, msg:
    uihandle = win32api.RegCreateKey(roothandle, uninstallkey)
win32api.RegSetValueEx(uihandle, "DisplayName", None, win32con.REG_SZ,
		       "Python "+sys.winver)
Esempio n. 20
0
class IconOverlay:

    _reg_clsid_ = '{4FC554DF-F0EE-4A4F-966C-9C49CCF14D59}'
    _reg_progid_ = 'TJG.PythonPackagesOverlayHandler'
    _reg_desc_ = 'Icon Overlay Handler to indicate Python packages'
    _public_methods_ = ['GetOverlayInfo', 'GetPriority', 'IsMemberOf']
    _com_interfaces_ = [shell.IID_IShellIconOverlayIdentifier]

    def GetOverlayInfo(self):
        return (r'C:\Program Files\TortoiseHg\icons\status\added.ico', 0,
                shellcon.ISIOI_ICONFILE)

    def GetPriority(self):
        return 50

    def IsMemberOf(self, fname, attributes):
        if os.path.exists(os.path.join(fname, "__init__.py")):
            return winerror.S_OK
        return winerror.E_FAIL


if __name__ == '__main__':
    import win32api
    import win32con
    import win32com.server.register

    win32com.server.register.UseCommandLine(IconOverlay)
    keyname = r'Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\PyPackageOverlay'
    key = win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, keyname)
    win32api.RegSetValue(key, None, win32con.REG_SZ, IconOverlay._reg_clsid_)
Esempio n. 21
0
def cmd_install(args):
    """
    Installs the CryVersionSelector on this machine.
    """
    if not HAS_WIN_MODULES:
        error_missing_windows_modules(args, "install")

    uninstall_integration()

    if getattr(sys, 'frozen', False):
        # when the current module is executable, we use it directly
        # otherwise we have to call python in the cmd line
        curr_module_path = os.path.abspath(sys.executable)
        engine_commands = [('add', 'Register Engine',
                            '"%s" add "%%1"' % curr_module_path),
                           ('1engine_gen', 'Generate Engine Solution',
                            '"%s" engine_gen "%%1"' % curr_module_path)]

        # --- extended, action, title, command
        # The first collumn defines extended action. The associated
        # commands will be displayed only when the user right-clicks an
        # object while also pressing the SHIFT key.
        # https://msdn.microsoft.com/en-us/library/cc144171(VS.85).aspx
        project_commands = [(False, 'edit', 'Launch Editor',
                             '"%s" edit "%%1"' % curr_module_path),
                            (False, '1open', 'Launch Game',
                             '"%s" open "%%1"' % curr_module_path),
                            (False, '2dedicated', 'Launch Dedicated Server',
                             '"%s" server "%%1"' % curr_module_path),
                            (False, '3package', 'Package Build',
                             '"%s" package "%%1"' % curr_module_path),
                            (False, '4metagen', 'Generate/Repair Metadata',
                             '"%s" metagen "%%1"' % curr_module_path),
                            (False, '5projgen', 'Generate Solution',
                             '"%s" projgen "%%1"' % curr_module_path),
                            (False, '6cmake-gui', 'Open CMake GUI',
                             '"%s" cmake-gui "%%1"' % curr_module_path),
                            (False, '7switch', 'Switch Engine Version',
                             '"%s" switch "%%1"' % curr_module_path),
                            (False, '8backup', 'Backup Project',
                             '"%s" backup "%%1"' % curr_module_path)]

        plugin_commands = [
            (False, 'register', 'Register Plugin',
             '"%s" add_plugin_gui "%%1"' % curr_module_path),
            (False, '1unregister', 'Unregister Plugin',
             '"%s" remove_plugin_gui "%%1"' % curr_module_path),
        ]
    else:
        curr_module_path = os.path.abspath(__file__)
        python_path = get_python_path()
        engine_commands = [
            ('add', 'Register Engine',
             '"%s" "%s" add "%%1"' % (python_path, curr_module_path)),
            ('1engine_gen', 'Generate Engine Solution',
             '"%s" "%s" engine_gen "%%1"' % (python_path, curr_module_path))
        ]

        project_commands = [
            (False, 'edit', 'Launch Editor',
             '"%s" "%s" edit "%%1"' % (python_path, curr_module_path)),
            (False, '1open', 'Launch Game',
             '"%s" "%s" open "%%1"' % (python_path, curr_module_path)),
            (False, '2dedicated', 'Launch Dedicated Server',
             '"%s" "%s" server "%%1"' % (python_path, curr_module_path)),
            (False, '3package', 'Package Build',
             '"%s" "%s" package "%%1"' % (python_path, curr_module_path)),
            (False, '4metagen', 'Generate/Repair Metadata',
             '"%s" "%s" metagen "%%1"' % (python_path, curr_module_path)),
            (False, '5projgen', 'Generate Solution',
             '"%s" "%s" projgen "%%1"' % (python_path, curr_module_path)),
            (False, '6cmake-gui', 'Open CMake GUI',
             '"%s" "%s" cmake-gui "%%1"' % (python_path, curr_module_path)),
            (False, '7switch', 'Switch Engine Version',
             '"%s" "%s" switch "%%1"' % (python_path, curr_module_path)),
            (False, '8backup', 'Backup Project',
             '"%s" "%s" backup "%%1"' % (python_path, curr_module_path))
        ]

        plugin_commands = [
            (False, 'register', 'Register Plugin',
             '"%s" "%s" add_plugin_gui "%%1"' %
             (python_path, curr_module_path)),
            (False, '1unregister', 'Unregister Plugin',
             '"%s" "%s" remove_plugin_gui "%%1"' %
             (python_path, curr_module_path)),
        ]

    key = False and win32con.HKEY_LOCAL_MACHINE or win32con.HKEY_CURRENT_USER
    hClassesRoot = win32api.RegOpenKeyEx(key, 'Software\\Classes')
    # https://msdn.microsoft.com/en-us/library/windows/desktop/cc144152(v=vs.85).aspx

    # .cryengine

    FriendlyTypeName = 'CryEngine version'
    ProgID = 'CrySelect.engine'
    AppUserModelID = 'CrySelect.engine'
    DefaultIcon = os.path.join(crypath.get_exec_dir(), 'editor_icon.ico')

    hProgID = win32api.RegCreateKey(hClassesRoot, ProgID)
    win32api.RegSetValueEx(hProgID, None, None, win32con.REG_SZ,
                           FriendlyTypeName)
    win32api.RegSetValueEx(hProgID, 'AppUserModelID', None, win32con.REG_SZ,
                           AppUserModelID)
    win32api.RegSetValueEx(hProgID, 'FriendlyTypeName', None, win32con.REG_SZ,
                           FriendlyTypeName)
    win32api.RegSetValue(hProgID, 'DefaultIcon', win32con.REG_SZ, DefaultIcon)

    # ---

    hShell = win32api.RegCreateKey(hProgID, 'shell')
    win32api.RegCloseKey(hProgID)

    for action, title, command in engine_commands:
        hAction = win32api.RegCreateKey(hShell, action)
        win32api.RegSetValueEx(hAction, None, None, win32con.REG_SZ, title)
        win32api.RegSetValueEx(hAction, 'Icon', None, win32con.REG_SZ,
                               DefaultIcon)
        win32api.RegSetValue(hAction, 'command', win32con.REG_SZ, command)
        win32api.RegCloseKey(hAction)

    action = 'add'
    win32api.RegSetValueEx(hShell, None, None, win32con.REG_SZ, action)
    win32api.RegCloseKey(hShell)

    # ---

    hCryProj = win32api.RegCreateKey(hClassesRoot,
                                     cryregistry.ENGINE_EXTENSION)
    win32api.RegSetValueEx(hCryProj, None, None, win32con.REG_SZ, ProgID)
    win32api.RegCloseKey(hCryProj)

    # .cryproject

    FriendlyTypeName = 'CryEngine project'
    ProgID = 'CrySelect.project'
    AppUserModelID = 'CrySelect.project'
    DefaultIcon = os.path.join(crypath.get_exec_dir(), 'editor_icon16.ico')

    hProgID = win32api.RegCreateKey(hClassesRoot, ProgID)
    win32api.RegSetValueEx(hProgID, None, None, win32con.REG_SZ,
                           FriendlyTypeName)
    win32api.RegSetValueEx(hProgID, 'AppUserModelID', None, win32con.REG_SZ,
                           AppUserModelID)
    win32api.RegSetValueEx(hProgID, 'FriendlyTypeName', None, win32con.REG_SZ,
                           FriendlyTypeName)
    win32api.RegSetValue(hProgID, 'DefaultIcon', win32con.REG_SZ, DefaultIcon)

    # ---

    hShell = win32api.RegCreateKey(hProgID, 'shell')
    win32api.RegCloseKey(hProgID)

    for extended, action, title, command in project_commands:
        hAction = win32api.RegCreateKey(hShell, action)
        win32api.RegSetValueEx(hAction, None, None, win32con.REG_SZ, title)
        win32api.RegSetValueEx(hAction, 'Icon', None, win32con.REG_SZ,
                               DefaultIcon)
        win32api.RegSetValue(hAction, 'command', win32con.REG_SZ, command)
        if extended:
            win32api.RegSetValueEx(hAction, 'extended', None, win32con.REG_SZ,
                                   '')

        win32api.RegCloseKey(hAction)

    action = 'edit'
    win32api.RegSetValueEx(hShell, None, None, win32con.REG_SZ, action)
    win32api.RegCloseKey(hShell)

    # ---

    hCryProj = win32api.RegCreateKey(hClassesRoot, '.cryproject')
    win32api.RegSetValueEx(hCryProj, None, None, win32con.REG_SZ, ProgID)
    win32api.RegCloseKey(hCryProj)

    # --- .cryplugin

    FriendlyTypeName = 'CryEngine plugin'
    ProgID = 'CrySelect.plugin'
    AppUserModelID = 'CrySelect.plugin'
    DefaultIcon = os.path.join(crypath.get_exec_dir(), 'editor_icon16.ico')

    hProgID = win32api.RegCreateKey(hClassesRoot, ProgID)
    win32api.RegSetValueEx(hProgID, None, None, win32con.REG_SZ,
                           FriendlyTypeName)
    win32api.RegSetValueEx(hProgID, 'AppUserModelID', None, win32con.REG_SZ,
                           AppUserModelID)
    win32api.RegSetValueEx(hProgID, 'FriendlyTypeName', None, win32con.REG_SZ,
                           FriendlyTypeName)
    win32api.RegSetValue(hProgID, 'DefaultIcon', win32con.REG_SZ, DefaultIcon)

    # ---

    hShell = win32api.RegCreateKey(hProgID, 'shell')
    win32api.RegCloseKey(hProgID)

    for extended, action, title, command, in plugin_commands:
        hAction = win32api.RegCreateKey(hShell, action)
        win32api.RegSetValueEx(hAction, None, None, win32con.REG_SZ, title)
        win32api.RegSetValueEx(hAction, 'Icon', None, win32con.REG_SZ,
                               DefaultIcon)
        win32api.RegSetValue(hAction, 'command', win32con.REG_SZ, command)
        if extended:
            win32api.RegSetValueEx(hAction, 'extended', None, win32con.REG_SZ,
                                   '')

        win32api.RegCloseKey(hAction)

    action = 'register'
    win32api.RegSetValueEx(hShell, None, None, win32con.REG_SZ, action)
    win32api.RegCloseKey(hShell)

    # ---

    hCryProj = win32api.RegCreateKey(hClassesRoot, '.cryplugin')
    win32api.RegSetValueEx(hCryProj, None, None, win32con.REG_SZ, ProgID)
    win32api.RegCloseKey(hCryProj)
Esempio n. 22
0
        win32api.RegSetValue(key,subKey,type,value) # 设置项的默认值
            Key:已经打开的项的句柄。
            subKey:所要设置的子项。
            Type:项值的类型,必须为 win32con.REG_SZ。
            Value:项值数据,为字符串。

        win32api.RegSetValueEx(key,valueName,reserved,type,value) # 要修改或重新设置注册表某一项的项值。如果项值存在,则修改该项值,如果不存在,则添加该项值。
            Key:要设置的项的句柄。
            valueName:要设置的项值名称。
            Reserved:保留,可以设为0。
            Type:项值的类型。
            Value:所要设置的值。

      如:
        # 将“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer”的默认值设为python
        win32api.RegSetValue(key,'',win32con.REG_SZ,'python')
        # 修改“Version”的值
        win32api.RegSetValueEx(key,'Version',0,win32con.REG_SZ,'7.0.2900.2180')

    7.  添加、删除项
        win32api.RegCreateKey(key,subKey) # 向注册表中添加项
        win32api.RegDeleteKey(key,subKey) # 删除注册表中的项
        两个函数的参数用法一样。参数含义如下:
            Key:已经打开的注册表项的句柄。
            subKey:所要操作(添加或删除)的子项。

      如:
        # 向“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer”添加子项“Python”
        win32api.RegCreateKey(key,'Python') # 此时会多一个“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\\Python”
        # 删除刚才创建的子项“Python”
        win32api.RegDeleteKey(key,'Python') # 没有此项时,会抛出错误
Esempio n. 23
0
def cmd_install(args):

    uninstall_integration()

    #---

    if getattr(sys, 'frozen', False):
        ScriptPath = os.path.abspath(sys.executable)
        engine_commands = (('add', 'Register engine',
                            '"%s" add "%%1"' % ScriptPath), )

        # --- extended, action, title, command
        # The first collumn difines extended action. The associated commands will be displayed only when the user right-clicks an object while also pressing the SHIFT key.
        # https://msdn.microsoft.com/en-us/library/cc144171(VS.85).aspx
        project_commands = (
            (False, 'edit', 'Launch editor', '"%s" edit "%%1"' % ScriptPath),
            (False, 'open', 'Launch game', '"%s" open "%%1"' % ScriptPath),
            (False, 'monodev', 'Edit code', '"%s" monodev "%%1"' % ScriptPath),
            (False, '_build', 'Build solution',
             '"%s" build "%%1"' % ScriptPath),
            (False, '_projgen', 'Generate solution',
             '"%s" projgen "%%1"' % ScriptPath),
            (False, '_switch', 'Switch engine version',
             '"%s" switch "%%1"' % ScriptPath),
            (False, '_deploy', 'Deploy build',
             '"%s" deploy "%%1"' % ScriptPath),
            (True, 'metagen', 'Generate/repair metadata',
             '"%s" metagen "%%1"' % ScriptPath),
        )
    else:
        ScriptPath = os.path.abspath(__file__)
        PythonPath = python3_path()
        engine_commands = (('add', 'Register engine', '"%s" "%s" add "%%1"' %
                            (PythonPath, ScriptPath)), )

        project_commands = (
            (False, 'edit', 'Launch editor',
             '"%s" "%s" edit "%%1"' % (PythonPath, ScriptPath)),
            (False, 'open', 'Launch game',
             '"%s" "%s" open "%%1"' % (PythonPath, ScriptPath)),
            (False, 'monodev', 'Edit code', '"%s" monodev "%%1"' % ScriptPath),
            (False, '_build', 'Build solution',
             '"%s" "%s" build "%%1"' % (PythonPath, ScriptPath)),
            (False, '_projgen', 'Generate solution',
             '"%s" "%s" projgen "%%1"' % (PythonPath, ScriptPath)),
            (False, '_switch', 'Switch engine version',
             '"%s" "%s" switch "%%1"' % (PythonPath, ScriptPath)),
            (False, '_deploy', 'Deploy build',
             '"%s" "%s" deploy "%%1"' % (PythonPath, ScriptPath)),
            (True, 'metagen', 'Generate/repair metadata',
             '"%s" "%s" metagen "%%1"' % (PythonPath, ScriptPath)),
        )

    #---

    current_user_is_admin = shell.IsUserAnAdmin()
    key = False and win32con.HKEY_LOCAL_MACHINE or win32con.HKEY_CURRENT_USER
    hClassesRoot = win32api.RegOpenKeyEx(key, 'Software\\Classes')
    #https://msdn.microsoft.com/en-us/library/windows/desktop/cc144152(v=vs.85).aspx

    #--- .cryengine

    FriendlyTypeName = 'CryEngine version'
    ProgID = 'CrySelect.engine'
    AppUserModelID = 'CrySelect.engine'
    DefaultIcon = os.path.abspath(
        os.path.join(os.path.dirname(ScriptPath), 'editor_icon.ico'))

    hProgID = win32api.RegCreateKey(hClassesRoot, ProgID)
    win32api.RegSetValueEx(hProgID, None, None, win32con.REG_SZ,
                           FriendlyTypeName)
    win32api.RegSetValueEx(hProgID, 'AppUserModelID', None, win32con.REG_SZ,
                           AppUserModelID)
    win32api.RegSetValueEx(hProgID, 'FriendlyTypeName', None, win32con.REG_SZ,
                           FriendlyTypeName)
    win32api.RegSetValue(hProgID, 'DefaultIcon', win32con.REG_SZ, DefaultIcon)

    #---

    hShell = win32api.RegCreateKey(hProgID, 'shell')
    win32api.RegCloseKey(hProgID)

    for action, title, command in engine_commands:
        hAction = win32api.RegCreateKey(hShell, action)
        win32api.RegSetValueEx(hAction, None, None, win32con.REG_SZ, title)
        win32api.RegSetValueEx(hAction, 'Icon', None, win32con.REG_SZ,
                               DefaultIcon)
        win32api.RegSetValue(hAction, 'command', win32con.REG_SZ, command)
        win32api.RegCloseKey(hAction)

    action = 'add'
    win32api.RegSetValueEx(hShell, None, None, win32con.REG_SZ, action)
    win32api.RegCloseKey(hShell)

    #---

    hCryProj = win32api.RegCreateKey(hClassesRoot,
                                     cryregistry.ENGINE_EXTENSION)
    win32api.RegSetValueEx(hCryProj, None, None, win32con.REG_SZ, ProgID)
    win32api.RegCloseKey(hCryProj)

    #--- .cryproject

    FriendlyTypeName = 'CryEngine project'
    ProgID = 'CrySelect.project'
    AppUserModelID = 'CrySelect.project'
    DefaultIcon = os.path.abspath(
        os.path.join(os.path.dirname(ScriptPath), 'editor_icon16.ico'))

    hProgID = win32api.RegCreateKey(hClassesRoot, ProgID)
    win32api.RegSetValueEx(hProgID, None, None, win32con.REG_SZ,
                           FriendlyTypeName)
    win32api.RegSetValueEx(hProgID, 'AppUserModelID', None, win32con.REG_SZ,
                           AppUserModelID)
    win32api.RegSetValueEx(hProgID, 'FriendlyTypeName', None, win32con.REG_SZ,
                           FriendlyTypeName)
    win32api.RegSetValue(hProgID, 'DefaultIcon', win32con.REG_SZ, DefaultIcon)

    #---

    hShell = win32api.RegCreateKey(hProgID, 'shell')
    win32api.RegCloseKey(hProgID)

    for extended, action, title, command in project_commands:
        hAction = win32api.RegCreateKey(hShell, action)
        win32api.RegSetValueEx(hAction, None, None, win32con.REG_SZ, title)
        win32api.RegSetValueEx(hAction, 'Icon', None, win32con.REG_SZ,
                               DefaultIcon)
        win32api.RegSetValue(hAction, 'command', win32con.REG_SZ, command)
        if extended:
            win32api.RegSetValueEx(hAction, 'extended', None, win32con.REG_SZ,
                                   '')

        win32api.RegCloseKey(hAction)

    action = 'edit'
    win32api.RegSetValueEx(hShell, None, None, win32con.REG_SZ, action)
    win32api.RegCloseKey(hShell)

    #---

    hCryProj = win32api.RegCreateKey(hClassesRoot, '.cryproject')
    win32api.RegSetValueEx(hCryProj, None, None, win32con.REG_SZ, ProgID)
    win32api.RegCloseKey(hCryProj)
Esempio n. 24
0
def RegisterFileExtensions(defPyIcon, defPycIcon, runCommand):
    """Register the core Python file extensions.
	
	   defPyIcon -- The default icon to use for .py files, in 'fname,offset' format.
	   defPycIcon -- The default icon to use for .pyc files, in 'fname,offset' format.
	   runCommand -- The command line to use for running .py files
	"""
    # Register the file extensions.
    pythonFileId = RegistryIDPyFile
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, ".py", win32con.REG_SZ,
                         pythonFileId)
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, pythonFileId,
                         win32con.REG_SZ, "Python File")
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT,
                         "%s\\CLSID" % pythonFileId, win32con.REG_SZ,
                         CLSIDPyFile)
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT,
                         "%s\\DefaultIcon" % pythonFileId, win32con.REG_SZ,
                         defPyIcon)
    base = "%s\\Shell" % RegistryIDPyFile
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + "\\Open",
                         win32con.REG_SZ, "Run")
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + "\\Open\\Command",
                         win32con.REG_SZ, runCommand)

    # Register the .PYC.
    pythonFileId = RegistryIDPycFile
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, ".pyc", win32con.REG_SZ,
                         pythonFileId)
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, pythonFileId,
                         win32con.REG_SZ, "Compiled Python File")
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT,
                         "%s\\DefaultIcon" % pythonFileId, win32con.REG_SZ,
                         defPycIcon)
    base = "%s\\Shell" % pythonFileId
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + "\\Open",
                         win32con.REG_SZ, "Run")
    win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + "\\Open\\Command",
                         win32con.REG_SZ, runCommand)
Esempio n. 25
0
#!/usr/bin/env python
#_*_coding:utf-8_*_
import win32api
import win32con

key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE,r"SOFTWARE\Classes\*\shell")
    
newKey = win32api.RegCreateKey(key,"YNote")
    
sub_key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE,r"SOFTWARE\Classes\*\shell\YNote")


   
newsubKey = win32api.RegCreateKey(sub_key,"command")
    
win32api.RegSetValue(newsubKey,"(Default)", win32con.REG_SZ,"\"C:\Program Files (x86)\Youdao\YoudaoNote\YoudaoNote.exe\" \"%1\"")