Regedit返回值null

时间:2018-04-04 13:17:14

标签: c# .net winforms regedit

有人帮助我。 为什么这段代码不能正常工作。 仍然返回null。

enter image description here

RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);

RegistryKey rk = hklm.OpenSubKey(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll",RegistryRights.ReadKey);

string valueName = "TcpPort";

1 个答案:

答案 0 :(得分:0)

您需要替换:

hklm.OpenSubKey(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll",RegistryRights.ReadKey);

hklm.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll",RegistryRights.ReadKey);