拒绝访问注册表项“[KEY_NAME]" [英] Access to the registry key '[KEY_NAME]' is denied

查看:35
本文介绍了拒绝访问注册表项“[KEY_NAME]"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Visual Basic 2008 编写一个小程序,用于翻转注册表项中特定 DWORD 的值

I'm writing a small program in Visual Basic 2008 that flips the values of specific DWORDs in a registry key

有问题的注册表项是:

'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{91801674-82d9-459a-9358-6e5cf3d81d21}\FxProperties'

我正在操纵的双字是{e0a941a0-88a2-4df5-8d6b-dd20bb06e8fb},4"

这是我为设置 DWORD 值而编写的代码行:

This is the line of code I wrote to set the DWORD's value is this:

Dim keyString = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{91801674-82d9-459a-9358-6e5cf3d81d21}\FxProperties"
My.Computer.Registry.SetValue(keyString, "{ad75efc0-8f48-4285-bfa8-40fb036cdab2},2", "00000000")

但我在运行时收到一个 UnauthorizedAccessException,指出对注册表项 [KEY_NAME] 的访问被拒绝."

But I get a UnauthorizedAccessException at runtime stating that "Access to the registry key [KEY_NAME] is denied."

我以管理员权限运行该程序,将应用程序的清单更改为包括:

I ran the program with Administrator privileges, changed the app's manifest to include:

<requestedExecutionLevel level="highestAvailable" uiAccess="false" />

但这也没有用.所以我搜索了几个论坛并尝试了这个:

But that didn't work either. So I searched a few forums and tried this:

Dim rkLM As RegistryKey = Registry.LocalMachine
Dim pRegKey As RegistryKey = rkLM.OpenSubKey("\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render\{91801674-82d9-459a-9358-6e5cf3d81d21}\FxProperties", True)
pRegKey.SetValue("{ad75efc0-8f48-4285-bfa8-40fb036cdab2},2", "00000000")

但这向我抛出了一个 NullReferenceException,指出未将对象引用设置为对象的实例."

But that threw a NullReferenceException at me stating "Object reference not set to an instance of an object."

有什么方法可以修改那个密钥,而不必以 SYSTEM 权限运行我的程序?

Is there any way I can modify that that key without having to run my program with SYSTEM privileges?

推荐答案

谢谢 Matt,我也尝试使用 requireAdministrator 运行它,但也无济于事.无论如何,我找到了解决方案,似乎问题出在我试图修改的注册表项的权限上.

Thanks Matt, I tried running it with requireAdministrator as well but that didn't help either. Anyway, I found the solution to this and it seems the problem lied with the permissions on the registry key that I was trying to modify.

完全控制权限仅授予TrustedInstaller组,因此我将完全控制授予管理员 组也是如此.

Full Control access was only given to the TrustedInstaller group, so I granted Full Control to the users in the Administrators group as well.

我使用 SYSTEM 权限启动了regedit">Sysinternals 的 PsExec 工具[psexec -si regedit] 并导航到我希望使用我的程序操作的键并使用 [Edit ->权限] 授予我自己的写访问权限.

I started 'regedit' with SYSTEM privileges using Sysinternals' PsExec tool [psexec -si regedit] and navigated to the key I wished to manipulate using my program and used [Edit -> Permissions] to grant write access to myself.

这样做之后,我的代码工作了:

After doing that, my code worked and this:

Dim keyString = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\" _
+ "MMDevices\Audio\Render\{91801674-82d9-459a-9358-6e5cf3d81d21}\FxProperties"

Dim regKey = "{ad75efc0-8f48-4285-bfa8-40fb036cdab2},2"

My.Computer.Registry.SetValue( _
keyString, regKey, "00000000", RegistryValueKind.DWord)

可以成功翻转 DWORD 的值.虽然这有效,但我想知道是否有办法做到这一点,而无需手动更改注册表子项的权限.

could successfully flip the value of the DWORD. Although this worked, I would like to know if there's a way to do this without having to manually change permissions on the registry subkey.

我在 C# 中找到了类似的问题和解决方案,给出了here但我无法将那里提到的 C# 代码成功转换为 VB.NET 代码.你能帮忙吗?

I found a similar problem and solution for this in C# given here but I couldn't successfully convert the C# code mentioned there to VB.NET code. Could you help with that?

这篇关于拒绝访问注册表项“[KEY_NAME]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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