Requested registry access is not allowed I want to access Remote Pc's Registry but it cant allow me to do so.
Below is my code
private static void CheckRemoteRegistry()
{
try {
string serverName = "DESKTOP-2ME3g20M";
NetworkShare share = new
NetworkShare(serverName, "C$", "ARIgTEAM", "02123541");
share.Connect();
String ProductName = string.Empty;
String InstanceName = string.Empty;
RegistryKey key;
RegistryKey key2;
RegistryKey Remotekey =
RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, serverName, RegistryView.Registry64);
if (Remotekey != null)
{
key = Remotekey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
key2 = Remotekey.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL");
if (key != null)
{
ProductName = key.GetValue("ProductName").ToString();
InstanceName = key.GetValue("MSSQLSERVER").ToString();
}
}
share.Disconnect();
}
catch(Exception ex) {
throw new Exception(ex.Message);
}
}
key = Remotekey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"); This Is Working
but
key2 = Remotekey.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL");
this code show's me this error.
If anyone is wondering.
Was able to solve the issue by granting permissions to the following area:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurePipeServers\winreg