如何从 ASP.NET 应用程序在 IIS 中写入注册表?

How to write in registry from ASP.NET App in IIS?

我尝试从 asp.net 应用程序中写入 Registry.LocalMachine。我使用以下代码,它可以在我的开发机器上运行:

string value = "some value";
RegistryKey clefDeRegistre = Registry.LocalMachine;
RegistryKey clefTapi = clefDeRegistre.OpenSubKey(@"SOFTWARE\SomeEditor\MySubKey", true);
if (clefTapi != null)
    {
        clefTapi.SetValue("Options", value);
    }

但是当我在我的服务器 (Windows Server 2008 R2) 上尝试这个时,它不起作用。

使用默认的应用程序池设置,我在尝试写入注册表时收到安全异常。所以我将应用程序池标识更改为 LocalSystem。

现在我没有收到任何异常,但密钥没有被修改。

Registry Virtualization 似乎有问题,但我不知道如何禁用它。

如果您的应用程序池处于 32 位模式,则密钥转到 SOFTWARE\Wow6432Node 分支。