_windows.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #*****************************************************************************
  2. # Copyright 2004-2008 Steve Menard
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. #*****************************************************************************
  17. from . import _jvmfinder
  18. try:
  19. import _winreg as winreg
  20. except ImportError:
  21. import winreg # in Py3, winreg has been moved
  22. # ------------------------------------------------------------------------------
  23. class WindowsJVMFinder(_jvmfinder.JVMFinder):
  24. """
  25. Linux JVM library finder class
  26. """
  27. def __init__(self):
  28. """
  29. Sets up members
  30. """
  31. # Call the parent constructor
  32. _jvmfinder.JVMFinder.__init__(self)
  33. # Library file name
  34. self._libfile = "jvm.dll"
  35. # Search methods
  36. self._methods = (self._get_from_java_home,
  37. self._get_from_registry)
  38. def _get_from_registry(self):
  39. """
  40. Retrieves the path to the default Java installation stored in the
  41. Windows registry
  42. :return: The path found in the registry, or None
  43. """
  44. try :
  45. jreKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
  46. r"SOFTWARE\JavaSoft\Java Runtime Environment")
  47. cv = winreg.QueryValueEx(jreKey, "CurrentVersion")
  48. versionKey = winreg.OpenKey(jreKey, cv[0])
  49. winreg.CloseKey(jreKey)
  50. cv = winreg.QueryValueEx(versionKey, "RuntimeLib")
  51. winreg.CloseKey(versionKey)
  52. return cv[0]
  53. except WindowsError:
  54. return None