I'm not sure why this is throwing an exception... The exception isn't very specific.. Am I missing something? :(
I'm essentially trying to update a registry value on a remote machine. On the RegistryKey Key
line, an exception is thrown: Object reference not set to an instance of an object.
This is because the key
is getting set to null
. However, if I shorten the OpenSubKey
value to just OpenSubKey("software",true);
it works just fine. But I need to get two subkeys deeper than Software. Is there a limitation on the OpenSubKey
class when it's used with the OpenRemoteBaseKey
class?
ServiceController service = new ServiceController();
service.MachineName = store;
try
{
//Enable Remote registry
string commandStart = @"/k sc \\" + store + " config remoteregistry start= auto && exit";
string commandStop = @"/k sc \\" + store + " config remoteregistry start= disabled && exit";
Process.Start("cmd.exe", commandStart);
System.Threading.Thread.Sleep(2000);
service.ServiceName = "remoteregistry";
service.Start();
//Disable User Input
RegistryKey key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, store).OpenSubKey(@"software\realvnc\vncserver",true);
key.SetValue("DisableLocalInputs", "1");
CheckIsDisabled(key);
//Re-enable User Input
key.SetValue("DisableLocalInputs", "0");
service.Stop();
System.Threading.Thread.Sleep(2000);
Process.Start("cmd.exe", commandStop);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Exception");
}