我想阅读DisplayName
和InstallDate
for uninstall注册表,但它只显示InstallDate
的结果,如何显示两者的结果?
ManagementScope scope = new ManagementScope("\\\\.\\root\\CIMV2");
scope.Connect();
string softwareRegLoc = @"Software\Microsoft\Windows\CurrentVersion\Uninstall";
ManagementClass registry = new ManagementClass(scope, new ManagementPath("StdRegProv"), null);
ManagementBaseObject inParams = registry.GetMethodParameters("EnumKey");
inParams["sSubKeyName"] = softwareRegLoc;
// Read Registry Key Names
ManagementBaseObject outParams = registry.InvokeMethod("EnumKey", inParams, null);
string[] programGuids = outParams["sNames"] as string[];
foreach (string subKeyName in programGuids)
{
inParams = registry.GetMethodParameters("GetStringValue");
inParams["sSubKeyName"] = softwareRegLoc + @"\" + subKeyName;
inParams["sValueName"] = "DisplayName";
inParams["sValueName"] = "InstallDate";
// Read Registry Value
outParams = registry.InvokeMethod("GetStringValue", inParams, null);
if (outParams.Properties["sValue"].Value != null)
{
Console.WriteLine($"Value: {outParams.Properties["sValue"].Value.ToString()}");
}
}
我有一种方法,但看起来代码重复,
inParams["sValueName"] = "DisplayName";
// Read Registry Value
outParams = registry.InvokeMethod("GetStringValue", inParams, null);
if (outParams.Properties["sValue"].Value != null)
{
Console.WriteLine($"Value: {outParams.Properties["sValue"].Value.ToString()}");
}
inParams["sValueName"] = "InstallDate";
// Read Registry Value
outParams = registry.InvokeMethod("GetStringValue", inParams, null);
if (outParams.Properties["sValue"].Value != null)
{
Console.WriteLine($"Value: {outParams.Properties["sValue"].Value.ToString()}");
}
还有其他方法吗?