用C#确定快速时间版本

本文关键字:时间 版本 | 更新日期: 2023-09-27 18:21:35

我正在编写一个C#应用程序,我需要确定系统上是否安装了quicktime以及安装的版本。这是在窗户上。

用C#确定快速时间版本

在谷歌上快速搜索后,该页面上出现了以下代码:

strComputer = "."
Set objWMIService = GetObject("winmgmts:''" & strComputer & "'root'cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_Product Where Name = 'QuickTime'")
If colItems.Count = 0 Then
    Wscript.Echo "QuickTime is not installed on this computer."
Else
    For Each objItem in colItems
        Wscript.Echo "QuickTime version: " & objItem.Version
    Next
End If

"等等!"你说,"那是VBScript,不是C#!"这是真的,但它是VBScript执行WMI查询。另一个快速的谷歌搜索找到了如何从C#进行WMI查询。

试试这个:

using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE'Microsoft'Windows'CurrentVersion'Uninstall"))
{
    if (key != null)
    {
        foreach (string subKeyName in key.GetSubKeyNames())
        {
            using (RegistryKey subKey = key.OpenSubKey(subKeyName))
            {
                if (subKey == null) continue;
                var displayName = subKey.GetValue("DisplayName") as string;
                if (displayName == null || !displayName.Equals("QuickTime")) continue;
                var version = subKey.GetValue("DisplayVersion");
                Console.WriteLine(displayName);
                Console.WriteLine(version);
            }
        }
    }
}