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)
python类winver()的实例源码
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)
def InitInstance(self):
# Use a registry path of "Python\Pythonwin Debugger
win32ui.SetAppName(win32ui.LoadString(win32ui.IDR_DEBUGGER))
win32ui.SetRegistryKey("Python %s" % (sys.winver,))
# We _need_ the Scintilla color editor.
# (and we _always_ get it now :-)
numMRU = win32ui.GetProfileVal("Settings","Recent File List Size", 10)
win32ui.LoadStdProfileSettings(numMRU)
self.LoadMainFrame()
# Display the interactive window if the user wants it.
from pywin.framework import interact
interact.CreateInteractiveWindowUserPreference()
# Load the modules we use internally.
self.LoadSystemModules()
# Load additional module the user may want.
self.LoadUserModules()
# win32ui.CreateDebuggerThread()
win32ui.EnableControlContainer()
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)
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
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)
def _find_localserver_exe(mustfind):
if not sys.platform.startswith("win32"):
return sys.executable
if pythoncom.__file__.find("_d") < 0:
exeBaseName = "pythonw.exe"
else:
exeBaseName = "pythonw_d.exe"
# First see if in the same directory as this .EXE
exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName )
if not os.path.exists(exeName):
# See if in our sys.prefix directory
exeName = os.path.join( sys.prefix, exeBaseName )
if not os.path.exists(exeName):
# See if in our sys.prefix/pcbuild directory (for developers)
if "64 bit" in sys.version:
exeName = os.path.join( sys.prefix, "PCbuild", "amd64", exeBaseName )
else:
exeName = os.path.join( sys.prefix, "PCbuild", exeBaseName )
if not os.path.exists(exeName):
# See if the registry has some info.
try:
key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver
path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key )
exeName = os.path.join( path, exeBaseName )
except (AttributeError,win32api.error):
pass
if not os.path.exists(exeName):
if mustfind:
raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
return None
return exeName
def _find_localserver_exe(mustfind):
if not sys.platform.startswith("win32"):
return sys.executable
if pythoncom.__file__.find("_d") < 0:
exeBaseName = "pythonw.exe"
else:
exeBaseName = "pythonw_d.exe"
# First see if in the same directory as this .EXE
exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName )
if not os.path.exists(exeName):
# See if in our sys.prefix directory
exeName = os.path.join( sys.prefix, exeBaseName )
if not os.path.exists(exeName):
# See if in our sys.prefix/pcbuild directory (for developers)
if "64 bit" in sys.version:
exeName = os.path.join( sys.prefix, "PCbuild", "amd64", exeBaseName )
else:
exeName = os.path.join( sys.prefix, "PCbuild", exeBaseName )
if not os.path.exists(exeName):
# See if the registry has some info.
try:
key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver
path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key )
exeName = os.path.join( path, exeBaseName )
except (AttributeError,win32api.error):
pass
if not os.path.exists(exeName):
if mustfind:
raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
return None
return exeName
def _doregister(mod_name, dll_name):
assert os.path.isfile(dll_name), "Shouldn't get here if the file doesn't exist!"
try:
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name))
except _winreg.error:
try:
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name))
except _winreg.error:
print "Could not find the existing '%s' module registered in the registry" % (mod_name,)
usage_and_die(4)
# Create the debug key.
sub_key = _winreg.CreateKey(key, "Debug")
_winreg.SetValue(sub_key, None, _winreg.REG_SZ, dll_name)
print "Registered '%s' in the registry" % (dll_name,)
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
def InitInstance(self):
# Allow "/nodde" and "/new" to optimize this!
if "/nodde" not in sys.argv and "/new" not in sys.argv:
if self.InitDDE():
return 1 # A remote DDE client is doing it for us!
else:
self.ddeServer = None
win32ui.SetRegistryKey("Python %s" % (sys.winver,)) # MFC automatically puts the main frame caption on!
app.CApp.InitInstance(self)
# Create the taskbar icon
win32ui.CreateDebuggerThread()
# Allow Pythonwin to host OCX controls.
win32ui.EnableControlContainer()
# Display the interactive window if the user wants it.
import interact
interact.CreateInteractiveWindowUserPreference()
# Load the modules we use internally.
self.LoadSystemModules()
# Load additional module the user may want.
self.LoadUserModules()
# Load the ToolBar state near the end of the init process, as
# there may be Toolbar IDs created by the user or other modules.
# By now all these modules should be loaded, so all the toolbar IDs loaded.
try:
self.frame.LoadBarState("ToolbarDefault")
except win32ui.error:
# MFC sucks. It does essentially "GetDlgItem(x)->Something", so if the
# toolbar with ID x does not exist, MFC crashes! Pythonwin has a trap for this
# but I need to investigate more how to prevent it (AFAIK, ensuring all the
# toolbars are created by now _should_ stop it!)
pass
# Finally process the command line arguments.
self.ProcessArgs(sys.argv)
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]
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)
def _find_localserver_exe(mustfind):
if not sys.platform.startswith("win32"):
return sys.executable
if pythoncom.__file__.find("_d") < 0:
exeBaseName = "pythonw.exe"
else:
exeBaseName = "pythonw_d.exe"
# First see if in the same directory as this .EXE
exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName )
if not os.path.exists(exeName):
# See if in our sys.prefix directory
exeName = os.path.join( sys.prefix, exeBaseName )
if not os.path.exists(exeName):
# See if in our sys.prefix/pcbuild directory (for developers)
if "64 bit" in sys.version:
exeName = os.path.join( sys.prefix, "PCbuild", "amd64", exeBaseName )
else:
exeName = os.path.join( sys.prefix, "PCbuild", exeBaseName )
if not os.path.exists(exeName):
# See if the registry has some info.
try:
key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver
path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key )
exeName = os.path.join( path, exeBaseName )
except (AttributeError,win32api.error):
pass
if not os.path.exists(exeName):
if mustfind:
raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
return None
return exeName
def InitInstance(self):
# Allow "/nodde" and "/new" to optimize this!
if "/nodde" not in sys.argv and "/new" not in sys.argv:
if self.InitDDE():
return 1 # A remote DDE client is doing it for us!
else:
self.ddeServer = None
win32ui.SetRegistryKey("Python %s" % (sys.winver,)) # MFC automatically puts the main frame caption on!
app.CApp.InitInstance(self)
# Create the taskbar icon
win32ui.CreateDebuggerThread()
# Allow Pythonwin to host OCX controls.
win32ui.EnableControlContainer()
# Display the interactive window if the user wants it.
from . import interact
interact.CreateInteractiveWindowUserPreference()
# Load the modules we use internally.
self.LoadSystemModules()
# Load additional module the user may want.
self.LoadUserModules()
# Load the ToolBar state near the end of the init process, as
# there may be Toolbar IDs created by the user or other modules.
# By now all these modules should be loaded, so all the toolbar IDs loaded.
try:
self.frame.LoadBarState("ToolbarDefault")
except win32ui.error:
# MFC sucks. It does essentially "GetDlgItem(x)->Something", so if the
# toolbar with ID x does not exist, MFC crashes! Pythonwin has a trap for this
# but I need to investigate more how to prevent it (AFAIK, ensuring all the
# toolbars are created by now _should_ stop it!)
pass
# Finally process the command line arguments.
self.ProcessArgs(sys.argv)
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]
def _doregister(mod_name, dll_name):
assert os.path.isfile(dll_name), "Shouldn't get here if the file doesn't exist!"
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name))
except winreg.error:
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name))
except winreg.error:
print("Could not find the existing '%s' module registered in the registry" % (mod_name,))
usage_and_die(4)
# Create the debug key.
sub_key = winreg.CreateKey(key, "Debug")
winreg.SetValue(sub_key, None, winreg.REG_SZ, dll_name)
print("Registered '%s' in the registry" % (dll_name,))
def _find_localserver_exe(mustfind):
if not sys.platform.startswith("win32"):
return sys.executable
if pythoncom.__file__.find("_d") < 0:
exeBaseName = "pythonw.exe"
else:
exeBaseName = "pythonw_d.exe"
# First see if in the same directory as this .EXE
exeName = os.path.join( os.path.split(sys.executable)[0], exeBaseName )
if not os.path.exists(exeName):
# See if in our sys.prefix directory
exeName = os.path.join( sys.prefix, exeBaseName )
if not os.path.exists(exeName):
# See if in our sys.prefix/pcbuild directory (for developers)
if "64 bit" in sys.version:
exeName = os.path.join( sys.prefix, "PCbuild", "amd64", exeBaseName )
else:
exeName = os.path.join( sys.prefix, "PCbuild", exeBaseName )
if not os.path.exists(exeName):
# See if the registry has some info.
try:
key = "SOFTWARE\\Python\\PythonCore\\%s\\InstallPath" % sys.winver
path = win32api.RegQueryValue( win32con.HKEY_LOCAL_MACHINE, key )
exeName = os.path.join( path, exeBaseName )
except (AttributeError,win32api.error):
pass
if not os.path.exists(exeName):
if mustfind:
raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
return None
return exeName
def _get_lib_path():
if os.name == 'nt':
if 'PyPy' in sys.version:
return os.path.join(sys.prefix, 'lib-python', sys.winver)
else:
return os.path.join(sys.prefix, 'Lib')
else:
return [x for x in sys.path if x.endswith('%s.%s' % sys.version_info[:2])][0]
def SetupEnvironment():
HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these...
KEY_QUERY_VALUE = 0x1
# Open the root key once, as this is quite slow on NT.
try:
keyName = "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % sys.winver
key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE , keyName, 0, KEY_QUERY_VALUE)
except (win32api.error, AttributeError):
key = None
try:
found = 0
if key is not None:
try:
__path__.append( win32api.RegQueryValue(key, "Extensions" ))
found = 1
except win32api.error:
# Nothing registered
pass
if not found:
try:
__path__.append( win32api.GetFullPathName( __path__[0] + "\\..\\win32comext") )
except win32api.error:
# Give up in disgust!
pass
# For the sake of developers, we also look up a "BuildPath" key
# If extension modules add support, we can load their .pyd's from a completely
# different directory (see the comments below)
try:
if key is not None:
global __build_path__
__build_path__ = win32api.RegQueryValue(key, "BuildPath")
__path__.append(__build_path__)
except win32api.error:
# __build_path__ neednt be defined.
pass
global __gen_path__
if key is not None:
try:
__gen_path__ = win32api.RegQueryValue(key, "GenPath")
except win32api.error:
pass
finally:
if key is not None:
key.Close()
# A Helper for developers. A sub-package's __init__ can call this help function,
# which allows the .pyd files for the extension to live in a special "Build" directory
# (which the win32com developers do!)
def SetupEnvironment():
HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these...
KEY_QUERY_VALUE = 0x1
# Open the root key once, as this is quite slow on NT.
try:
keyName = "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % sys.winver
key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE , keyName, 0, KEY_QUERY_VALUE)
except (win32api.error, AttributeError):
key = None
try:
found = 0
if key is not None:
try:
__path__.append( win32api.RegQueryValue(key, "Extensions" ))
found = 1
except win32api.error:
# Nothing registered
pass
if not found:
try:
__path__.append( win32api.GetFullPathName( __path__[0] + "\\..\\win32comext") )
except win32api.error:
# Give up in disgust!
pass
# For the sake of developers, we also look up a "BuildPath" key
# If extension modules add support, we can load their .pyd's from a completely
# different directory (see the comments below)
try:
if key is not None:
global __build_path__
__build_path__ = win32api.RegQueryValue(key, "BuildPath")
__path__.append(__build_path__)
except win32api.error:
# __build_path__ neednt be defined.
pass
global __gen_path__
if key is not None:
try:
__gen_path__ = win32api.RegQueryValue(key, "GenPath")
except win32api.error:
pass
finally:
if key is not None:
key.Close()
# A Helper for developers. A sub-package's __init__ can call this help function,
# which allows the .pyd files for the extension to live in a special "Build" directory
# (which the win32com developers do!)
def SetupEnvironment():
HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these...
KEY_QUERY_VALUE = 0x1
# Open the root key once, as this is quite slow on NT.
try:
keyName = "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % sys.winver
key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE , keyName, 0, KEY_QUERY_VALUE)
except (win32api.error, AttributeError):
key = None
try:
found = 0
if key is not None:
try:
__path__.append( win32api.RegQueryValue(key, "Extensions" ))
found = 1
except win32api.error:
# Nothing registered
pass
if not found:
try:
__path__.append( win32api.GetFullPathName( __path__[0] + "\\..\\win32comext") )
except win32api.error:
# Give up in disgust!
pass
# For the sake of developers, we also look up a "BuildPath" key
# If extension modules add support, we can load their .pyd's from a completely
# different directory (see the comments below)
try:
if key is not None:
global __build_path__
__build_path__ = win32api.RegQueryValue(key, "BuildPath")
__path__.append(__build_path__)
except win32api.error:
# __build_path__ neednt be defined.
pass
global __gen_path__
if key is not None:
try:
__gen_path__ = win32api.RegQueryValue(key, "GenPath")
except win32api.error:
pass
finally:
if key is not None:
key.Close()
# A Helper for developers. A sub-package's __init__ can call this help function,
# which allows the .pyd files for the extension to live in a special "Build" directory
# (which the win32com developers do!)
def SetupEnvironment():
HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these...
KEY_QUERY_VALUE = 0x1
# Open the root key once, as this is quite slow on NT.
try:
keyName = "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % sys.winver
key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE , keyName, 0, KEY_QUERY_VALUE)
except (win32api.error, AttributeError):
key = None
try:
found = 0
if key is not None:
try:
__path__.append( win32api.RegQueryValue(key, "Extensions" ))
found = 1
except win32api.error:
# Nothing registered
pass
if not found:
try:
__path__.append( win32api.GetFullPathName( __path__[0] + "\\..\\win32comext") )
except win32api.error:
# Give up in disgust!
pass
# For the sake of developers, we also look up a "BuildPath" key
# If extension modules add support, we can load their .pyd's from a completely
# different directory (see the comments below)
try:
if key is not None:
global __build_path__
__build_path__ = win32api.RegQueryValue(key, "BuildPath")
__path__.append(__build_path__)
except win32api.error:
# __build_path__ neednt be defined.
pass
global __gen_path__
if key is not None:
try:
__gen_path__ = win32api.RegQueryValue(key, "GenPath")
except win32api.error:
pass
finally:
if key is not None:
key.Close()
# A Helper for developers. A sub-package's __init__ can call this help function,
# which allows the .pyd files for the extension to live in a special "Build" directory
# (which the win32com developers do!)