RegistryKey.OpenRemoteBaseKey Error

  • Thread starter Thread starter csharp_helpwanted
  • Start date Start date
C

csharp_helpwanted

steps..

first, I'm creating a connection by mapping a network drive to the pc
second, the map drive connection was successful I try to read a certian
registry key/value (that is a valid reg item)
third, I disconnect the network drive connection

it works great the first time

but if i run it again on the same pc anytime after that I get the following
error.
the Remote Procedue Call Failed

I have confirmed that the network drive is connecting fine with
administrator priviliges

any ideas


readvalue code below

------------------------------------

/// <summary>
/// To read a registry value.
/// input:
/// output: string of registry value or null
/// </summary>
public string ReadValue(string remoteIP, RegistryHive baseRegistryKey,
string currentSubKey, string currentValueName)
{

RegistryKey rk = null;
RegistryKey sk = null;
string result;

try
{
rk = RegistryKey.OpenRemoteBaseKey(baseRegistryKey, remoteIP);
// when i run this the 2nd time on the same ip
// i get error the Remote Procedue Call Failed
try
{
sk = rk.OpenSubKey(currentSubKey);
try
{
result = sk.GetValue(currentValueName).ToString();
}
catch
{
result = "VALUE NOT FOUND";
}
}
catch
{
result = "KEY NOT FOUND";
}
}
catch(Exception e)
{
result = e.Message.ToString(); //return the error the Remote
Procedue Call Failed
}

return result;

}
 
Back
Top