Trying to read the last succesful Windows Update time from a remote machine, but getting an error on the key
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\
sample code:
var hive = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, machineName);
var soft = hive.OpenSubKey("SOFTWARE");
var micro = soft.OpenSubKey("Microsoft");
var wind = micro.OpenSubKey("Windows");
var currver = wind.OpenSubKey("CurrentVersion");
var wu = currver.OpenSubKey("WindowsUpdate"); // returns NULL
var au = wu.OpenSubKey("Auto Update"); // throws exception "Object referece not set to an instance of an object"
var res = au.OpenSubKey("Results");
var inst = res.OpenSubKey("Install");
var lastUpdate = inst.GetValue("LastSuccessTime").ToString();
Console.WriteLine(lastUpdate);
I have verified the key is correct, and I'm not sure what the problem is.
EDIT The error I receive is
Object reference not set to an instance of an object.
because the subkey "WindowsUpdate" is returning NULL.
wu
is null. – Ron BeyerOpenRemoteBaseKey
takes a third parameter: RegistryView. – Johnny Mopp