簡體   English   中英

如何檢查計算機上安裝了哪個版本的Windows Media Player?

[英]How to check what version of Windows Media Player is installed on the machine?

據我所知,Windows Media Player 10是WPF MediaElement正常運行的最低要求。 什么是通過編程(從.NET)以編程方式檢查WMP是否存在及其版本的一種不錯的方式?

我在安裝程序中使用的方法是檢查此注冊表值:

HKLM
Software\Microsoft\MediaPlayer\PlayerUpgrade
PlayerVersion

PlayerVersion值將設置為類似“ 10,0,0,0”的字符串。 (請注意,逗號用來分隔數字,而不是句點。)您需要提取第一個數字(主版本)並確保它是10或更高。

我找不到有關如何檢測WMP的任何官方文檔,但是上述方法似乎可以在Windows和WMP的當前版本中正常使用。

請注意,如果安裝了WMP9(Windows XP附帶的版本),則當您嘗試使用MediaElement時,您的應用程序不會崩潰,但是控件將不呈現任何內容,並且警告消息將打印到調試器。

如果您的應用程序僅在Vista或更高版本上使用,則無需擔心其中任何一個,因為Vista隨附WMP10。

您可以通過以下方法檢查系統上安裝的所有產品:

SelectQuery allProductsQuery = new SelectQuery("Win32_Product");

ManagementObjectSearcher allProducts =
new ManagementObjectSearcher(allProductsQuery);

foreach(ManagementObject product in allProducts.Get())
{
Console.WriteLine("Product {0} is at version {1}",
product.Properties["Name"].Value,
product.Properties["Version"].Value);
}

您需要添加“使用System.Management”和對“ System.Management.dll”的引用。

要獲取特定產品的信息,您可以優化查詢或在所有產品中搜索產品。

我找到了這個解決方案:

FileVersionInfo inf = FileVersionInfo.GetVersionInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Windows Media Player", "wmplayer.exe"));
        if (inf.FileVersion.StartsWith("9"))
        {...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM