使用C#确定QuickTime版本

3

我正在编写一个C#应用程序,需要确定系统是否安装了QuickTime以及其版本号。这是在Windows上进行的。

2个回答

6

快速的谷歌搜索找到了来自此页面的以下代码:

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#!”没错,但它是用于WMI查询的VBScript。另一个快速的谷歌搜索可以找到C#如何进行WMI查询


确实聪明。即使您不了解VBScript,它仍然是C#版本的不错伪代码。 - Robert Harvey

2

试试这个:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接