本文介绍了Vista + VB.NET - 在写入HKEY_LOCAL_MACHINE时拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的程序能够编辑驻留在HKEY_LOCAL_MACHINE中的注册表项中的值

I want my program to be able to edit a values within a registry key that resides in 'HKEY_LOCAL_MACHINE'

    My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\XYZ", "MyValue", "MyData")

以上在Windows XP中可以正常工作,但在Vista中抛出UnauthorizedAccessException。

The above works fine in Windows XP, but throws an UnauthorizedAccessException in Vista.

推荐答案

您正在运行Vista的UAC功能。不会让您写入HKLM配置单元中的任意位置,因为您没有使用管理权限。

You are running into Vista's UAC feature. It will not let you write to arbitrary places in the HKLM hive because you are not running with Administrative priviledges.

有两种方法可以解决这个问题。

There are two ways to work around this issue


  1. 运行程序

  2. 选择另一个地方,也可能是HKCU来存储数据

第二个选项要好得多,因为它允许您的应用程序使用非管理员权限运行,您不能总是假设您的用户。

The second option is much better as it allows your application to run with non-Admin priviledges which you can't always assume your user has.

这是一篇非常详细的UAC文章。它不是100%的编程材料,但它给出了一个很好的解释,究竟是什么,你可以希望将其与您的特定程序相关联:

Here is a fairly detailed article on UAC. It's not 100% programming material but it gives a good explanation as to what exactly it is and you can hopefully relate that to your particular program: http://technet.microsoft.com/en-us/library/cc709691.aspx

这篇关于Vista + VB.NET - 在写入HKEY_LOCAL_MACHINE时拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 17:47