本文整理汇总了Python中_winreg.HKEY_CLASSES_ROOT属性的典型用法代码示例。如果您正苦于以下问题:Python _winreg.HKEY_CLASSES_ROOT属性的具体用法?Python _winreg.HKEY_CLASSES_ROOT怎么用?Python _winreg.HKEY_CLASSES_ROOT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类_winreg
的用法示例。
在下文中一共展示了_winreg.HKEY_CLASSES_ROOT属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_registry_read_error
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import HKEY_CLASSES_ROOT [as 别名]
def test_registry_read_error(self):
import _winreg
class MockWinreg(object):
def OpenKey(self, key, name):
if key != _winreg.HKEY_CLASSES_ROOT:
raise WindowsError(5, "Access is denied")
return _winreg.OpenKey(key, name)
def __getattr__(self, name):
return getattr(_winreg, name)
mimetypes._winreg = MockWinreg()
try:
mimetypes.init()
finally:
mimetypes._winreg = _winreg
示例2: MyComputer
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import HKEY_CLASSES_ROOT [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
示例3: RunEmailClient
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import HKEY_CLASSES_ROOT [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
)
#===============================================================================
示例4: GetIrfanViewPath
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import HKEY_CLASSES_ROOT [as 别名]
def GetIrfanViewPath(self):
"""
Get the path of IrfanView's install-dir through querying the
Windows registry.
"""
try:
iv_reg = _winreg.OpenKey(
_winreg.HKEY_CLASSES_ROOT,
"\\Applications\\i_view32.exe\\shell\\open\\command"
)
IrfanViewPath =_winreg.QueryValue(iv_reg, None)
_winreg.CloseKey(iv_reg)
IrfanViewPath=IrfanViewPath[:-5]
IrfanViewPath=IrfanViewPath[1:-1]
except WindowsError:
IrfanViewPath = None
return IrfanViewPath
示例5: getWindowsPDFViewer
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import HKEY_CLASSES_ROOT [as 别名]
def getWindowsPDFViewer():
try:
import _winreg
# HKCR/.pdf: gives the class of the PDF program.
# Example : AcroRead.Document or FoxitReader.Document
key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, ".pdf")
pdfClass = _winreg.QueryValue(key, "")
# HKCR/<class>/shell/open/command: the path to the PDF viewer program
# Example: "C:\Program Files\Acrobat 8.0\acroread.exe" "%1"
key2 = _winreg.OpenKey(
_winreg.HKEY_CLASSES_ROOT, pdfClass + r"\shell\open\command")
# Almost every PDF program out there accepts passing the PDF path
# as the argument, so we don't parse the arguments from the
# registry, just get the program path.
path = _winreg.QueryValue(key2, "").split('"')[1]
if fileExists(path):
return path
except:
pass
return None
# get a windows environment variable in its native unicode format, or None
# if not found
示例6: RegisterPythonServer
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import HKEY_CLASSES_ROOT [as 别名]
def RegisterPythonServer(filename, progids=None, verbose=0):
if progids:
if isinstance(progids, basestring):
progids = [progids]
# we know the CLSIDs we need, but we might not be an admin user
# and otherwise unable to register them. So as long as the progids
# exist and the DLL points at our version, assume it already is.
why_not = None
for progid in progids:
try:
clsid = pythoncom.MakeIID(progid)
except pythoncom.com_error:
# no progid - not registered.
break
# have a CLSID - open it.
try:
HKCR = _winreg.HKEY_CLASSES_ROOT
hk = _winreg.OpenKey(HKCR, "CLSID\\%s" % clsid)
dll = _winreg.QueryValue(hk, "InprocServer32")
except WindowsError:
# no CLSID or InProcServer32 - not good!
break
if os.path.basename(dll) != os.path.basename(pythoncom.__file__):
why_not = "%r is registered against a different Python version (%s)" % (progid, dll)
break
else:
#print "Skipping registration of '%s' - already registered" % filename
return
# needs registration - see if its likely!
try:
from win32com.shell.shell import IsUserAnAdmin
except ImportError:
print "Can't import win32com.shell - no idea if you are an admin or not?"
is_admin = False
else:
try:
is_admin = IsUserAnAdmin()
except pythoncom.com_error:
# old, less-secure OS - assume *is* admin.
is_admin = True
if not is_admin:
msg = "%r isn't registered, but I'm not an administrator who can register it." % progids[0]
if why_not:
msg += "\n(registration check failed as %s)" % why_not
# throw a normal "class not registered" exception - we don't report
# them the same way as "real" errors.
raise pythoncom.com_error(winerror.CO_E_CLASSSTRING, msg, None, -1)
# so theoretically we are able to register it.
cmd = '%s "%s" --unattended > nul 2>&1' % (win32api.GetModuleFileName(0), filename)
if verbose:
print "Registering engine", filename
# print cmd
rc = os.system(cmd)
if rc:
print "Registration command was:"
print cmd
raise RuntimeError("Registration of engine '%s' failed" % filename)