在 Windows 7 上打开注册表项时出现问题 [英] Problem opening registry key on Windows 7

查看:53
本文介绍了在 Windows 7 上打开注册表项时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码过去适用于 Vista(和 Windows XP),但升级到 Windows 7 后,它现在失败并显示错误:

This code used to work on Vista (and Windows XP) but after an upgrade to Windows 7 it now fails with the error shown:

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32
>>> import _winreg
>>> h1 = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)        
>>> key = r'SOFTWARE\Python\PythonCore\2.6\InstallPath'
>>> h2 = _winreg.OpenKey(h1, key, 0, _winreg.KEY_ALL_ACCESS)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
WindowsError: [Error 5] Access is denied

我相当确定这是 Windows 7 中安全模型更改的结果,但到目前为止我尝试的各种搜索都没有找到我可以用作答案的结果.

I'm fairly sure this is the result of changes in the security model in Windows 7, but various searches I tried have turned up nothing I can use as an answer so far.

(不是说它应该相关,而是为了避免你为什么要那样做?"响应,这是一个开发人员的实用程序,它可以在多个 Python 安装之间切换注册表,以用于多项目环境我们需要更多地控制正在使用的 Python 版本以及可用的包,而不是像 virtualenv 可以提供.)

(Not that it should be relevant, but to stave off "why would you do that?" responses, this is for a developer's utility which can switch the registry between multiple installations of Python, for use in a multi-project environment where we need more control over which version of Python is in use, and what packages are available, than things like virtualenv can provide.)

登录用户是管理员.此外,我已经尽可能完全关闭了 UAC(用户访问控制)内容(不正确...请参阅下一个编辑),就像以前从 Vista 升级到 Windows 之前的情况一样7.

The logged-in user is an Administrator. Also, I've turned off the UAC (User Access Control) stuff as completely as one can (not true... see next edit), as was previously the case before the upgrade from Vista to Windows 7.

编辑 2: 正如我在下面自己的回答中所指出的,在关闭 UAC 后我没有重新启动,所以它仍然设置为默认值.显然这会导致拒绝访问错误(正如我通过将 UAC 设置为默认和从不进行测试所确认的那样).

Edit 2: As noted in my own answer below, I hadn't rebooted after turning off UAC, so it was still set to the default. Apparently this results in the Access denied error (as I confirmed by testing with UAC set to Default and to Never).

推荐答案

这是一个用户错误,由 Windows 7 中对 UAC 功能实现方式的更改加剧或触发.

This was a user mistake, compounded or triggered by changes in Windows 7 to how the UAC feature is implemented.

在 Vista 中,令人讨厌的用户访问控制功能是二进制的,无论是打开还是关闭.在已更改为提供四个粒度级别的 Windows 7 上:

In Vista, the much-detested User Access Control feature was binary, either on or off. On Windows 7 that has been changed to provide four levels of granularity:

  • 始终通知(当程序或用户尝试更改设置时)
  • 默认(仅在程序尝试进​​行更改时通知,并使屏幕变暗)
  • 不调暗通知(与默认相同,但在通知时不调暗屏幕)
  • 从不通知(对于程序或用户更改)

我的错误是在将 UAC 功能降低到从不通知级别后没有重新启动.(Vista 主动要求您重新启动,而 Windows 7 似乎更被动一些.)

My mistake was in not rebooting after dropping the UAC feature down to the Never Notify level. (Vista was aggressive about requesting that you reboot, while Windows 7 seems to be slightly more passive.)

这篇关于在 Windows 7 上打开注册表项时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆