V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
explist
V2EX  ›  Python

注册表操作疑问

  •  
  •   explist · 2017-02-15 12:52:15 +08:00 · 1946 次点击
    这是一个创建于 2633 天前的主题,其中的信息可能已经有所发展或是发生改变。

    以下代码为何老是出现: PermissionError: [WinError 5] 拒绝访问 异常?

    import winreg as reg

    def proReg():

    subkey = '*\shell'
    key = reg.OpenKey(reg.HKEY_CLASSES_ROOT,subkey)
    with key:
        reg.SetValue(key,'runas',reg.REG_SZ,'TEST')   # 这里抛出异常
        with reg.OpenKey(key,'runas',0,reg.KEY_WRITE) as nkey:
            reg.SetValueEx(nkey,'NoWorkingDirectory',0,reg.REG_SZ,'')
    

    if name == 'main':

       proReg()
    
    2 条回复    2017-02-15 15:13:08 +08:00
    progmboy
        1
    progmboy  
       2017-02-15 13:43:28 +08:00 via iPhone   ❤️ 2
    这个键是高权限的呀,已管理员运行就行了
    explist
        2
    explist  
    OP
       2017-02-15 15:13:08 +08:00
    行家一出手,.... 谢谢
    @progmboy
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2218 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 09:16 · PVG 17:16 · LAX 02:16 · JFK 05:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.