如何显示DisplayName和InstallDate,它只显示InstallDate的结果

问题描述 投票:0回答:1

我想阅读DisplayNameInstallDate 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()}");
            }
        }
c# registry
1个回答
0
投票

我有一种方法,但看起来代码重复,

 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()}");
            }

还有其他方法吗?

© www.soinside.com 2019 - 2024. All rights reserved.