Guest User

Untitled

a guest
Oct 18th, 2011
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- encoding: utf-8 -*-
  3. #
  4. # script to register Python 2.0 or later for use with win32all
  5. # and other extensions that require Python registry settings
  6. #
  7. # written by Joakim L?w for Secret Labs AB / PythonWare
  8. #
  9. # source:
  10. # http://www.pythonware.com/products/works/articles/regpy20.htm
  11.  
  12. import sys
  13.  
  14. from _winreg import *
  15.  
  16. # tweak as necessary
  17. version = sys.version[:3]
  18. installpath = sys.prefix
  19.  
  20. regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
  21. installkey = "InstallPath"
  22. pythonkey = "PythonPath"
  23. pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
  24.     installpath, installpath, installpath
  25. )
  26.  
  27. def RegisterPy():
  28.     try:
  29.         reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
  30.     except EnvironmentError:
  31.         try:
  32.             reg = CreateKey(HKEY_LOCAL_MACHINE, regpath)
  33.             SetValue(reg, installkey, REG_SZ, installpath)
  34.             SetValue(reg, pythonkey, REG_SZ, pythonpath)
  35.             CloseKey(reg)
  36.         except:
  37.             print "*** Unable to register!"
  38.             return
  39.         print "--- Python", version, "is now registered!"
  40.         return
  41.     if (QueryValue(reg, installkey) == installpath and
  42.         QueryValue(reg, pythonkey) == pythonpath):
  43.         CloseKey(reg)
  44.         print "=== Python", version, "is already registered!"
  45.         return
  46.     CloseKey(reg)
  47.     print "*** Unable to register!"
  48.     print "*** You probably have another Python installation!"
  49.  
  50. def UnRegisterPy():
  51.     try:
  52.         reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
  53.     except EnvironmentError:
  54.         print "*** Python not registered?!"
  55.         return
  56.     try:
  57.         DeleteKey(reg, installkey)
  58.         DeleteKey(reg, pythonkey)
  59.         DeleteKey(HKEY_LOCAL_MACHINE, regpath)
  60.     except:
  61.         print "*** Unable to un-register!"
  62.     else:
  63.         print "--- Python", version, "is no longer registered!"
  64.  
  65. if __name__ == "__main__":
  66.     # Register python's distribution
  67.     RegisterPy()
  68.     # If you want to unregister python's distribution, just comment the upper line and uncomment the following line
  69.     #UnRegisterPy()
Advertisement
Add Comment
Please, Sign In to add comment