本文整理汇总了Python中win32api.RegQueryValueEx方法的典型用法代码示例。如果您正苦于以下问题:Python win32api.RegQueryValueEx方法的具体用法?Python win32api.RegQueryValueEx怎么用?Python win32api.RegQueryValueEx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32api
的用法示例。
在下文中一共展示了win32api.RegQueryValueEx方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _win32_getvalue
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [as 别名]
def _win32_getvalue(key,name,default=''):
""" Read a value for name from the registry key.
In case this fails, default is returned.
"""
try:
# Use win32api if available
from win32api import RegQueryValueEx
except ImportError:
# On Python 2.0 and later, emulate using winreg
import winreg
RegQueryValueEx = winreg.QueryValueEx
try:
return RegQueryValueEx(key,name)
except:
return default
示例2: _win32_getvalue
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [as 别名]
def _win32_getvalue(key,name,default=''):
""" Read a value for name from the registry key.
In case this fails, default is returned.
"""
try:
# Use win32api if available
from win32api import RegQueryValueEx
except ImportError:
# On Python 2.0 and later, emulate using _winreg
import _winreg
RegQueryValueEx = _winreg.QueryValueEx
try:
return RegQueryValueEx(key,name)
except:
return default
示例3: _GetServiceShortName
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [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.
示例4: __FindSvcDeps
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [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)
示例5: testValues
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [as 别名]
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)
示例6: FindHelpPath
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [as 别名]
def FindHelpPath(helpFile, helpDesc, searchPaths):
# See if the current registry entry is OK
import os, win32api, win32con
try:
key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Help", 0, win32con.KEY_ALL_ACCESS)
try:
try:
path = win32api.RegQueryValueEx(key, helpDesc)[0]
if FileExists(os.path.join(path, helpFile)):
return os.path.abspath(path)
except win32api.error:
pass # no registry entry.
finally:
key.Close()
except win32api.error:
pass
for pathLook in searchPaths:
if FileExists(os.path.join(pathLook, helpFile)):
return os.path.abspath(pathLook)
pathLook = os.path.join(pathLook, "Help")
if FileExists(os.path.join( pathLook, helpFile)):
return os.path.abspath(pathLook)
raise error("The help file %s can not be located" % helpFile)
示例7: get_user_paths
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [as 别名]
def get_user_paths():
try:
keyh = win32api.RegOpenKeyEx(win32con.HKEY_USERS, None , 0, win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE | win32con.KEY_READ)
except:
return 0
paths = []
subkeys = win32api.RegEnumKeyEx(keyh)
for subkey in subkeys:
try:
subkeyh = win32api.RegOpenKeyEx(keyh, subkey[0] + "\\Environment" , 0, win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE | win32con.KEY_READ)
except:
pass
else:
subkey_count, value_count, mod_time = win32api.RegQueryInfoKey(subkeyh)
try:
path, type = win32api.RegQueryValueEx(subkeyh, "PATH")
paths.append((subkey[0], path))
except:
pass
return paths
示例8: get_system_path
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [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()
示例9: __getitem__
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [as 别名]
def __getitem__(self, item):
item = str(item)
# is it data?
try:
return self.massageIncomingRegistryValue(win32api.RegQueryValueEx(self.keyhandle, item))
except:
pass
# it's probably a key then
try:
return RegistryDict(self.keyhandle, item, win32con.KEY_ALL_ACCESS)
except:
pass
# must not be there
raise KeyError, item
示例10: StartYardServer
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [as 别名]
def StartYardServer(self):
try:
rkey = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Webers\\Y.A.R.D")
path = RegQueryValueEx(rkey, "program")[0]
if not os.path.exists(path):
raise Exception
except:
raise self.Exception(
"Please start Yards.exe first and configure it."
)
try:
hProcess = CreateProcess(
None,
path,
None,
None,
0,
CREATE_NEW_CONSOLE,
None,
None,
STARTUPINFO()
)[0]
except Exception, exc:
raise eg.Exception(FormatError(exc[0]))
示例11: check_masterPassword
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [as 别名]
def check_masterPassword(self):
accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\Martin Prikryl\WinSCP 2\Configuration\Security',
0, accessRead)
thisName = str(win32api.RegQueryValueEx(key, 'UseMasterPassword')[0])
if thisName == '0':
return False
else:
return True
示例12: get_default_database
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [as 别名]
def get_default_database(self):
accessRead = win32con.KEY_READ | win32con.KEY_ENUMERATE_SUB_KEYS | win32con.KEY_QUERY_VALUE
key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, 'Software\\ACS\\PuTTY Connection Manager', 0, accessRead)
thisName = str(win32api.RegQueryValueEx(key, 'DefaultDatabase')[0])
if thisName:
return thisName
else:
return ' '
示例13: RegGetValue
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [as 别名]
def RegGetValue(root, key):
"""This utility function returns a value in the registry
without having to open the key first. Only available on
Windows platforms with a version of Python that can read the
registry. Returns the same thing as
SCons.Util.RegQueryValueEx, except you just specify the entire
path to the value, and don't have to bother opening the key
first. So:
Instead of:
k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows\CurrentVersion')
out = SCons.Util.RegQueryValueEx(k,
'ProgramFilesDir')
You can write:
out = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir')
"""
# I would use os.path.split here, but it's not a filesystem
# path...
p = key.rfind('\\') + 1
keyp = key[:p-1] # -1 to omit trailing slash
val = key[p:]
k = RegOpenKeyEx(root, keyp)
return RegQueryValueEx(k,val)
示例14: GetItemsCurrentValue
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [as 别名]
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)
示例15: _GetRegistryValue
# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import RegQueryValueEx [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