我想使用Microsoft.Win32.Registry
. 我可以这样做是一个像这样的reg文件:
swreg = File.AppendText(strRegPath); //Opens the file:
swreg.WriteLine(@"[HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\OMI Account Manager\Accounts\user@domain.com");
swreg.WriteLine("\"DCEmail\"=dword:00000002");
swreg.WriteLine("\"POP3 Server\"=\"10.0.0.200\"");
swreg.WriteLine("\"POP3 Port\"=dword:0000006e");
这将创建一个 reg 文件,我可以执行创建 reg 密钥的文件。我曾尝试使用类似的方法Microsoft.Win32.Registry
:
var RKOutlook = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\Outlook\OMI Account Manager\Accounts");
if (RKOutlook.OpenSubKey("user@domain.com") == null)
{
RKOutlook.CreateSubKey("user@domain.com");
RKOutlook = RKOutlook.OpenSubKey("user@domain.com", true);
}
但是我收到一个System.NullReferenceException was unhandled
错误。如何在不使用 reg 文件的情况下直接写入注册表?