Python win32con.REG_SZ Examples

The following are 27 code examples of win32con.REG_SZ(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32con , or try the search function .
Example #1
Source File: recipe-174627.py    From code with MIT License 6 votes vote down vote up
def __setitem__(self, item, value):
        item = str(item)
        pyvalue = type(value)
        if pyvalue is dict or isinstance(value, RegistryDict):
            d = RegistryDict(self.keyhandle, item)
            d.clear()
            d.update(value)
            return
        if pyvalue is str:
            valuetype = win32con.REG_SZ
        elif pyvalue is int:
            valuetype = win32con.REG_DWORD
        else:
            valuetype = win32con.REG_BINARY
            value = 'PyPickle' + cPickle.dumps(value)
        win32api.RegSetValueEx(self.keyhandle, item, 0, valuetype, value) 
Example #2
Source File: test_win32api.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def testNotifyChange(self):
        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)

        evt = win32event.CreateEvent(None,0,0,None)
        ## REG_NOTIFY_CHANGE_LAST_SET - values
        ## REG_CHANGE_NOTIFY_NAME - keys
        ## REG_NOTIFY_CHANGE_SECURITY - security descriptor
        ## REG_NOTIFY_CHANGE_ATTRIBUTES
        win32api.RegNotifyChangeKeyValue(win32con.HKEY_CURRENT_USER,1,win32api.REG_NOTIFY_CHANGE_LAST_SET,evt,True)
        ret_code=win32event.WaitForSingleObject(evt,0)
        # Should be no change.
        self.failUnless(ret_code==win32con.WAIT_TIMEOUT)
        change()
        # Our event should now be in a signalled state.
        ret_code=win32event.WaitForSingleObject(evt,0)
        self.failUnless(ret_code==win32con.WAIT_OBJECT_0) 
Example #3
Source File: regutil.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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) 
Example #4
Source File: regutil.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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) 
Example #5
Source File: regutil.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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) 
Example #6
Source File: regutil.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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) 
Example #7
Source File: regutil.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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) 
Example #8
Source File: rtd_function.py    From pyxll-examples with The Unlicense 6 votes vote down vote up
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_)

# make sure the example RTD server is registered 
Example #9
Source File: test_win32api.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def testValues(self):
        key_name = r'PythonTestHarness\win32api'
        ## tuples containing value name, value type, data
        values=(
            (None, win32con.REG_SZ, 'This is default unnamed value'),
            ('REG_SZ', win32con.REG_SZ,'REG_SZ text data'),
            ('REG_EXPAND_SZ', win32con.REG_EXPAND_SZ, '%systemdir%'),
            ## REG_MULTI_SZ value needs to be a list since strings are returned as a list
            ('REG_MULTI_SZ', win32con.REG_MULTI_SZ, ['string 1','string 2','string 3','string 4']),
            ('REG_DWORD', win32con.REG_DWORD, 666),
            ('REG_BINARY', win32con.REG_BINARY, str2bytes('\x00\x01\x02\x03\x04\x05\x06\x07\x08\x01\x00')),
            )

        hkey = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER, key_name)
        for value_name, reg_type, data in values:
            win32api.RegSetValueEx(hkey, value_name, None, reg_type, data)

        for value_name, orig_type, orig_data in values:
            data, typ=win32api.RegQueryValueEx(hkey, value_name)
            self.assertEqual(typ, orig_type)
            self.assertEqual(data, orig_data) 
Example #10
Source File: recipe-174627.py    From code with MIT License 5 votes vote down vote up
def massageIncomingRegistryValue((obj, objtype)):
        if objtype == win32con.REG_BINARY and obj[:8]=='PyPickle':
            obj = obj[8:]
            return cPickle.loads(obj)
        elif objtype == win32con.REG_NONE:
            return None
        elif objtype in (win32con.REG_SZ, win32con.REG_EXPAND_SZ, win32con.REG_RESOURCE_LIST, win32con.REG_LINK, win32con.REG_BINARY, win32con.REG_DWORD, win32con.REG_DWORD_LITTLE_ENDIAN, win32con.REG_DWORD_BIG_ENDIAN, win32con.REG_MULTI_SZ):
            return obj
        raise NotImplementedError, "Registry type 0x%08X not supported" % (objtype,) 
Example #11
Source File: firewall.py    From code with MIT License 5 votes vote down vote up
def set(self, portspec, scope, enabled, name):
        scope = scope or self.SCOPE_ALL
        value = self._pack(portspec)
        data = self._pack(portspec, scope, enabled, name)
        self.hKey[value] = (data, Con.REG_SZ) 
Example #12
Source File: recipe-576431.py    From code with MIT License 5 votes vote down vote up
def modifyVariableInRegister( name , value ):
    key = win32api.RegOpenKey( win32con.HKEY_CURRENT_USER,"Environment",0,win32con.KEY_ALL_ACCESS)
    if not key : raise
    win32api.RegSetValueEx( key , name , 0 , win32con.REG_SZ , value )
    win32api.RegCloseKey( key ) 
Example #13
Source File: recipe-528896.py    From code with MIT License 5 votes vote down vote up
def WriteRegistryValue(hiveKey, key, name, data, typeId=win32con.REG_SZ):
    """ Write one value to Windows registry. If 'name' is empty string, writes default value.
        Creates subkeys as necessary"""
    try:
        keyHandle = OpenRegistryKey(hiveKey, key)
        win32api.RegSetValueEx(keyHandle, name, 0, typeId, data)
        win32api.RegCloseKey(keyHandle)
    except Exception, e:
        print "WriteRegistryValue failed:", hiveKey, name, e 
Example #14
Source File: recipe-528896.py    From code with MIT License 5 votes vote down vote up
def Test():
    TestRegistryWriteRead(win32con.HKEY_LOCAL_MACHINE, "Software\\AAAAA", "", "this is a default value", win32con.REG_SZ)
    TestRegistryWriteRead(win32con.HKEY_LOCAL_MACHINE, "Software\\AAAAA", "Data-SZ", "this is a string", win32con.REG_SZ)
    TestRegistryWriteRead(win32con.HKEY_LOCAL_MACHINE, "Software\\AAAAA", "Data-BINARY", '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09', win32con.REG_BINARY)
    TestRegistryWriteRead(win32con.HKEY_LOCAL_MACHINE, "Software\\AAAAA", "Data-DWORD", 0x01234567, win32con.REG_DWORD)
    DeleteRegistryKey(win32con.HKEY_LOCAL_MACHINE, "Software\\AAAAA") 
Example #15
Source File: msw.py    From wxGlade with MIT License 5 votes vote down vote up
def __setitem__(self, name, value):
        if isinstance(value, (tuple, list)):
            value = list(map(str, value))
            win32api.RegSetValueEx( self.handle, name, None, win32con.REG_MULTI_SZ, value)
        elif isinstance(value, bytes):
            win32api.RegSetValueEx( self.handle, name, None, win32con.REG_SZ, value.decode("UTF8"))
        else:
            win32api.RegSetValueEx( self.handle, name, None, win32con.REG_SZ, str(value)) 
Example #16
Source File: firewall.py    From code with MIT License 5 votes vote down vote up
def set(self, exepath, scope, enabled, name):
        scope = scope or self.SCOPE_ALL
        value = self._pack(exepath)
        data = self._pack(exepath, scope, enabled, name)
        self.hKey[value] = (data, Con.REG_SZ) 
Example #17
Source File: regedit.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def OnAddValue(self,command, code):
		from pywin.mfc import dialog
		val = dialog.GetSimpleInput("New value", "", "Add new value")
		if val is None: return # cancelled.
		hitem = self.hierList.GetSelectedItem()
		item = self.hierList.ItemFromHandle(hitem)
		if SafeApply(win32api.RegSetValue, (item.keyRoot, item.keyName, win32con.REG_SZ, val)):
			# Simply re-select the current item to refresh the right spitter.
			self.PerformItemSelected(item)
#			self.Select(hitem, commctrl.TVGN_CARET) 
Example #18
Source File: earthWallpaper.py    From Tools with MIT License 5 votes vote down vote up
def setWallPaper(imagepath='download/cache_wallpaper.png'):
	keyex = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)
	win32api.RegSetValueEx(keyex, "WallpaperStyle", 0, win32con.REG_SZ, "0")
	win32api.RegSetValueEx(keyex, "TileWallpaper", 0, win32con.REG_SZ, "0")
	win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, imagepath, win32con.SPIF_SENDWININICHANGE) 
Example #19
Source File: register.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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) 
Example #20
Source File: register.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _set_subkeys(keyName, valueDict, base=win32con.HKEY_CLASSES_ROOT):
  hkey = win32api.RegCreateKey(base, keyName)
  try:
    for key, value in valueDict.iteritems():
      win32api.RegSetValueEx(hkey, key, None, win32con.REG_SZ, value)
  finally:
    win32api.RegCloseKey(hkey) 
Example #21
Source File: win32serviceutil.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def SetServiceCustomOption(serviceName, option, value):
    try:
        serviceName = serviceName._svc_name_
    except AttributeError:
        pass
    key = win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Services\\%s\\Parameters" % serviceName)
    try:
        if type(value)==type(0):
            win32api.RegSetValueEx(key, option, 0, win32con.REG_DWORD, value);
        else:
            win32api.RegSetValueEx(key, option, 0, win32con.REG_SZ, value);
    finally:
        win32api.RegCloseKey(key) 
Example #22
Source File: win32serviceutil.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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)

# Utility functions for Services, to allow persistant properties. 
Example #23
Source File: regutil.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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) 
Example #24
Source File: regutil.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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) 
Example #25
Source File: regedit.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def SetItemsCurrentValue(self, item, valueName, value):
		# ** Assumes already checked is a string.
		hkey = win32api.RegOpenKey(item.keyRoot, item.keyName , 0, win32con.KEY_SET_VALUE)
		try:
			win32api.RegSetValueEx(hkey, valueName, 0, win32con.REG_SZ, value)
		finally:
			win32api.RegCloseKey(hkey) 
Example #26
Source File: regedit.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def GetItemsCurrentValue(self, item, valueName):
		hkey = win32api.RegOpenKey(item.keyRoot, item.keyName)
		try:
			val, type = win32api.RegQueryValueEx(hkey, valueName)
			if type != win32con.REG_SZ:
				raise TypeError("Only strings can be edited")
			return val
		finally:
			win32api.RegCloseKey(hkey) 
Example #27
Source File: win32serviceutil.py    From ironpython2 with Apache License 2.0 4 votes vote down vote up
def InstallPerfmonForService(serviceName, iniName, dllName = None):
    # If no DLL name, look it up in the INI file name
    if not dllName: # May be empty string!
        dllName = win32api.GetProfileVal("Python", "dll", "", iniName)
    # Still not found - look for the standard one in the same dir as win32service.pyd
    if not dllName:
        try:
            tryName = os.path.join(os.path.split(win32service.__file__)[0], "perfmondata.dll")
            if os.path.isfile(tryName):
                dllName = tryName
        except AttributeError:
            # Frozen app? - anyway, can't find it!
            pass
    if not dllName:
        raise ValueError("The name of the performance DLL must be available")
    dllName = win32api.GetFullPathName(dllName)
    # Now setup all the required "Performance" entries.
    hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\%s" % (serviceName), 0, win32con.KEY_ALL_ACCESS)
    try:
        subKey = win32api.RegCreateKey(hkey, "Performance")
        try:
            win32api.RegSetValueEx(subKey, "Library", 0, win32con.REG_SZ, dllName)
            win32api.RegSetValueEx(subKey, "Open", 0, win32con.REG_SZ, "OpenPerformanceData")
            win32api.RegSetValueEx(subKey, "Close", 0, win32con.REG_SZ, "ClosePerformanceData")
            win32api.RegSetValueEx(subKey, "Collect", 0, win32con.REG_SZ, "CollectPerformanceData")
        finally:
            win32api.RegCloseKey(subKey)
    finally:
        win32api.RegCloseKey(hkey)
    # Now do the "Lodctr" thang...

    try:
        import perfmon
        path, fname = os.path.split(iniName)
        oldPath = os.getcwd()
        if path:
            os.chdir(path)
        try:
            perfmon.LoadPerfCounterTextStrings("python.exe " + fname)
        finally:
            os.chdir(oldPath)
    except win32api.error, details:
        print "The service was installed OK, but the performance monitor"
        print "data could not be loaded.", details