English 中文(简体)
无法写入HKEY_LOCAL_MACHINE软件下的注册表
原标题:Cannot Write to the Registry under HKEY_LOCAL_MACHINESoftware

我正在编写一个应用程序,需要创建一个隐藏在登录屏幕和控制面板用户小程序中的特殊用户帐户。通过将用户名为0的<code>DWORD</code>值写入下面的注册表项,我能够实现这个目标:

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWinlogonSpecialAccountsUserList

问题是,在开启UAC的Windows7下,无论我尝试什么,我都无法以编程方式向上面的键写入值。

据我所知,除非您使用管理权限运行,否则在打开UAC的Windows 7上不允许向某些密钥写入。我添加了一个应用程序清单requestedExecutionLevel=“requireAdministrator”uiAccess=“false”,当我的程序运行时,我接受UAC提示,我的帐户是Administrators的成员,但我仍然无法写入上述注册表项。

我还需要做什么?在任何应用程序配置中,如何在HKEY_LOCAL_MACHINESOFTWARE下写入键和值?

进一步信息。。。当我的程序运行时,不会抛出任何错误,而且它似乎在写入值。我的猜测是,Windows正在虚拟化我写作的位置。如果我要隐藏这个特殊的用户帐户,我需要写到实际位置,而不是虚拟位置。

最佳回答

可能该程序在64位操作系统上作为32位程序运行?在这种情况下,我建议您搜索在HKEY_LOCAL_MACHINESOFTWAREWow6432Node子项下创建的值。

您可以阅读有关此类虚拟化的更多信息此处。您可以使用KEY_WOW64_32KEY标志在某些API中可以使用完整注册表而无需虚拟化。

问题回答

将值写入注册表

string user = Environment.UserDomainName + "\" + Environment.UserName;

RegistrySecurity rs = new RegistrySecurity();

rs.AddAccessRule(new RegistryAccessRule(user,
    RegistryRights.WriteKey | RegistryRights.ChangePermissions,
    InheritanceFlags.None, PropagationFlags.None, AccessControlType.Deny));

RegistryKey rk = null;
try
{
  rk = Registry.CurrentUser.CreateSubKey("SOFTWARE\TEST", 
                                   RegistryKeyPermissionCheck.Default, rs);
  rk.SetValue("NAME", "IROSH);
  rk.SetValue("FROM", "SRI LANKA");
}

这可能与他们在Vista中添加的重定向有关。如果您试图从代码中读取注册表值,如果您能得到您期望的值,我会很好奇。你可能还想启动RegMon,看看你是否能看到重定向可能迫使你去哪里。

RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun",true);
rk.SetValue("Name", "Value");




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签