3
我正在編寫一個C#應用程序,我需要確定是否在系統上安裝了quicktime以及哪個版本。 這是在窗戶上。使用C#確定quicktime版本
我正在編寫一個C#應用程序,我需要確定是否在系統上安裝了quicktime以及哪個版本。 這是在窗戶上。使用C#確定quicktime版本
快速谷歌搜索從this page打開了下面的代碼:
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。另一個快速谷歌搜索變成了how to do WMI queries from C#。
試試這個:
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);
}
}
}
}
聰明,確實如此。即使你不知道VBScript,它仍然是C#版本的體面僞代碼。 – 2012-01-28 00:40:11
謝謝,我會看看我能否得到這個工作。 – Zarxrax 2012-01-28 01:16:46