當前位置: 首頁>>代碼示例>>Python>>正文


Python win32con.HKEY_LOCAL_MACHINE屬性代碼示例

本文整理匯總了Python中win32con.HKEY_LOCAL_MACHINE屬性的典型用法代碼示例。如果您正苦於以下問題:Python win32con.HKEY_LOCAL_MACHINE屬性的具體用法?Python win32con.HKEY_LOCAL_MACHINE怎麽用?Python win32con.HKEY_LOCAL_MACHINE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在win32con的用法示例。


在下文中一共展示了win32con.HKEY_LOCAL_MACHINE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: DumpRegistry

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def DumpRegistry(root, level=0):
    # A recursive dump of the remote registry to test most functions.
    h = wincerapi.CeRegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, None)
    level_prefix = " " * level
    index = 0
    # Enumerate values.
    while 1:
        try:
            name, data, typ = wincerapi.CeRegEnumValue(root, index)
        except win32api.error:
            break
        print "%s%s=%s" % (level_prefix, name, repr(str(data)))
        index = index+1
    # Now enumerate all keys.
    index=0
    while 1:
        try:
            name, klass = wincerapi.CeRegEnumKeyEx(root, index)
        except win32api.error:
            break
        print "%s%s\\" % (level_prefix, name)
        subkey = wincerapi.CeRegOpenKeyEx(root, name)
        DumpRegistry(subkey, level+1)
        index = index+1 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:cerapi.py

示例2: _GetServiceShortName

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def _GetServiceShortName(longName):
    # looks up a services name
    # from the display name
    # Thanks to Andy McKay for this code.
    access = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
    hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services", 0, access)
    num = win32api.RegQueryInfoKey(hkey)[0]
    longName = longName.lower()
    # loop through number of subkeys
    for x in range(0, num):
    # find service name, open subkey
        svc = win32api.RegEnumKey(hkey, x)
        skey = win32api.RegOpenKey(hkey, svc, 0, access)
        try:
            # find display name
            thisName = str(win32api.RegQueryValueEx(skey, "DisplayName")[0])
            if thisName.lower() == longName:
                return svc
        except win32api.error:
            # in case there is no key called DisplayName
            pass
    return None

# Open a service given either it's long or short name. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:win32serviceutil.py

示例3: __FindSvcDeps

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def __FindSvcDeps(findName):
    if type(findName) is pywintypes.UnicodeType: findName = str(findName)
    dict = {}
    k = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services")
    num = 0
    while 1:
        try:
            svc = win32api.RegEnumKey(k, num)
        except win32api.error:
            break
        num = num + 1
        sk = win32api.RegOpenKey(k, svc)
        try:
            deps, typ = win32api.RegQueryValueEx(sk, "DependOnService")
        except win32api.error:
            deps = ()
        for dep in deps:
            dep = dep.lower()
            dep_on = dict.get(dep, [])
            dep_on.append(svc)
            dict[dep]=dep_on

    return __ResolveDeps(findName, dict) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:win32serviceutil.py

示例4: get_system_path

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def get_system_path():
	# HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
	key_string = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
	try:
		keyh = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, key_string , 0, win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE | win32con.KEY_READ)
	except:
		return None
		
	try:
		path, type = win32api.RegQueryValueEx(keyh, "PATH")
		return path
	except:
		return None
				
#name=sys.argv[1]
#if not os.path.exists(name):
	#print name, "does not exist!"
	#sys.exit() 
開發者ID:51x,項目名稱:WHP,代碼行數:20,代碼來源:windows-privesc-check.py

示例5: _GetRegistryValue

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def _GetRegistryValue(key, val, default = None):
	# val is registry value - None for default val.
	try:
		hkey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, key)
		return win32api.RegQueryValueEx(hkey, val)[0]
	except win32api.error:
		try:
			hkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, key)
			return win32api.RegQueryValueEx(hkey, val)[0]
		except win32api.error:
			return default 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:app.py

示例6: FindTabNanny

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def FindTabNanny():
	try:
		return __import__("tabnanny")
	except ImportError:
		pass
	# OK - not in the standard library - go looking.
	filename = "tabnanny.py"
	try:
		path = win32api.RegQueryValue(win32con.HKEY_LOCAL_MACHINE, "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % (sys.winver))
	except win32api.error:
		print "WARNING - The Python registry does not have an 'InstallPath' setting"
		print "          The file '%s' can not be located" % (filename)
		return None
	fname = os.path.join(path, "Tools\\Scripts\\%s" % filename)
	try:
		os.stat(fname)
	except os.error:
		print "WARNING - The file '%s' can not be located in path '%s'" % (filename, path)
		return None

	tabnannyhome, tabnannybase = os.path.split(fname)
	tabnannybase = os.path.splitext(tabnannybase)[0]
	# Put tab nanny at the top of the path.
	sys.path.insert(0, tabnannyhome)
	try:
		return __import__(tabnannybase)
	finally:
		# remove the tab-nanny from the path
		del sys.path[0] 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:31,代碼來源:scriptutils.py

示例7: ListAllHelpFiles

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def ListAllHelpFiles():
	ret = []
	ret = _ListAllHelpFilesInRoot(win32con.HKEY_LOCAL_MACHINE)
	# Ensure we don't get dups.
	for item in _ListAllHelpFilesInRoot(win32con.HKEY_CURRENT_USER):
		if item not in ret:
			ret.append(item)
	return ret 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:help.py

示例8: DumpPythonRegistry

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def DumpPythonRegistry():
    try:
        h = wincerapi.CeRegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\PythonPath" % sys.winver)
    except win32api.error:
        print "The remote device does not appear to have Python installed"
        return 0
    path, typ = wincerapi.CeRegQueryValueEx(h, None)
    print "The remote PythonPath is '%s'" % (str(path), )
    h.Close()
    return 1 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:cerapi.py

示例9: RemoveSourceFromRegistry

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def RemoveSourceFromRegistry(appName, eventLogType = "Application"):
    """Removes a source of messages from the event log.
    """

    # Delete our key
    try:
        win32api.RegDeleteKey(win32con.HKEY_LOCAL_MACHINE, \
                     "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s" % (eventLogType, appName))
    except win32api.error, exc:
        if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
            raise 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:win32evtlogutil.py

示例10: FormatMessage

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def FormatMessage( eventLogRecord, logType="Application" ):
    """Given a tuple from ReadEventLog, and optionally where the event
    record came from, load the message, and process message inserts.

    Note that this function may raise win32api.error.  See also the
    function SafeFormatMessage which will return None if the message can
    not be processed.
    """

    # From the event log source name, we know the name of the registry
    # key to look under for the name of the message DLL that contains
    # the messages we need to extract with FormatMessage. So first get
    # the event log source name...
    keyName = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s" % (logType, eventLogRecord.SourceName)

    # Now open this key and get the EventMessageFile value, which is
    # the name of the message DLL.
    handle = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, keyName)
    try:
        dllNames = win32api.RegQueryValueEx(handle, "EventMessageFile")[0].split(";")
        # Win2k etc appear to allow multiple DLL names
        data = None
        for dllName in dllNames:
            try:
                # Expand environment variable strings in the message DLL path name,
                # in case any are there.
                dllName = win32api.ExpandEnvironmentStrings(dllName)

                dllHandle = win32api.LoadLibraryEx(dllName, 0, win32con.LOAD_LIBRARY_AS_DATAFILE)
                try:
                    data = win32api.FormatMessageW(win32con.FORMAT_MESSAGE_FROM_HMODULE,
                                    dllHandle, eventLogRecord.EventID, langid, eventLogRecord.StringInserts)
                finally:
                    win32api.FreeLibrary(dllHandle)
            except win32api.error:
                pass # Not in this DLL - try the next
            if data is not None:
                break
    finally:
        win32api.RegCloseKey(handle)
    return data or u'' # Don't want "None" ever being returned. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:43,代碼來源:win32evtlogutil.py

示例11: UnregisterHelpFile

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def UnregisterHelpFile(helpFile, helpDesc = None):
	"""Unregister a help file in the registry.

           helpFile -- the base name of the help file.
           helpDesc -- A description for the help file.  If None, the helpFile param is used.
	"""
	key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Help", 0, win32con.KEY_ALL_ACCESS)
	try:
		try:
			win32api.RegDeleteValue(key, helpFile)
		except win32api.error, exc:
			import winerror
			if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
				raise
	finally:
		win32api.RegCloseKey(key)
	
	# Now de-register with Python itself.
	if helpDesc is None: helpDesc = helpFile
	try:
		win32api.RegDeleteKey(GetRootKey(), 
		                     BuildDefaultPythonKey() + "\\Help\\%s" % helpDesc)	
	except win32api.error, exc:
		import winerror
		if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
			raise 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:28,代碼來源:regutil.py

示例12: LocatePythonServiceExe

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def LocatePythonServiceExe(exeName = None):
    if not exeName and hasattr(sys, "frozen"):
        # If py2exe etc calls this with no exeName, default is current exe.
        return sys.executable

    # Try and find the specified EXE somewhere.  If specifically registered,
    # use it.  Otherwise look down sys.path, and the global PATH environment.
    if exeName is None:
        if os.path.splitext(win32service.__file__)[0].endswith("_d"):
            exeName = "PythonService_d.exe"
        else:
            exeName = "PythonService.exe"
    # See if it exists as specified
    if os.path.isfile(exeName): return win32api.GetFullPathName(exeName)
    baseName = os.path.splitext(os.path.basename(exeName))[0]
    try:
        exeName = win32api.RegQueryValue(win32con.HKEY_LOCAL_MACHINE,
                                         "Software\\Python\\%s\\%s" % (baseName, sys.winver))
        if os.path.isfile(exeName):
            return exeName
        raise RuntimeError("The executable '%s' is registered as the Python " \
                           "service exe, but it does not exist as specified" \
                           % exeName)
    except win32api.error:
        # OK - not there - lets go a-searchin'
        for path in [sys.prefix] + sys.path:
            look = os.path.join(path, exeName)
            if os.path.isfile(look):
                return win32api.GetFullPathName(look)
        # Try the global Path.
        try:
            return win32api.SearchPath(None, exeName)[0]
        except win32api.error:
            msg = "%s is not correctly registered\nPlease locate and run %s, and it will self-register\nThen run this service registration process again." % (exeName, exeName)
            raise error(msg) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:37,代碼來源:win32serviceutil.py

示例13: InstallPythonClassString

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
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. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:win32serviceutil.py

示例14: SetServiceCustomOption

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:win32serviceutil.py

示例15: GetServiceCustomOption

# 需要導入模塊: import win32con [as 別名]
# 或者: from win32con import HKEY_LOCAL_MACHINE [as 別名]
def GetServiceCustomOption(serviceName, option, defaultValue = None):
    # First param may also be a service class/instance.
    # This allows services to pass "self"
    try:
        serviceName = serviceName._svc_name_
    except AttributeError:
        pass
    key = win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Services\\%s\\Parameters" % serviceName)
    try:
        try:
            return win32api.RegQueryValueEx(key, option)[0]
        except win32api.error:  # No value.
            return defaultValue
    finally:
        win32api.RegCloseKey(key) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:win32serviceutil.py


注:本文中的win32con.HKEY_LOCAL_MACHINE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。