我需要以编程方式找到已安装的quicktime版本。以前我正在检查注册表项HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall
以获取quicktime。
但是在最新的quicktime更新版本(7.5版)中,它不起作用。
我在vbscript中发现了这段代码,但无法弄清楚如何在vb.net中执行此操作。
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
请告诉我如何找出快速时间的版本。
答案 0 :(得分:2)
首先在项目中添加对Microsoft WMI Scripting V1.2 Library
的引用。
然后,您需要在代码页的顶部导入这些名称空间:
Imports System.Runtime.InteropServices
Imports WbemScripting
以下是一个例子:
Private Sub CheckVersion()
Dim service As SWbemServicesEx = Nothing
Dim collection As SWbemObjectSet = Nothing
Dim item As SWbemObjectEx = Nothing
Try
Dim strComputer As String = "."
Dim version As String = Nothing
service = DirectCast(GetObject(String.Concat("winmgmts:\\", strComputer, "\root\cimv2")), SWbemServicesEx)
collection = service.ExecQuery("Select * From Win32_Product Where Name = 'QuickTime'")
If ((collection Is Nothing) OrElse (collection.Count = 0)) Then
MessageBox.Show("QuickTime is not installed on this computer", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
For i As Integer = 0 To (collection.Count - 1)
item = DirectCast(collection.ItemIndex(i), SWbemObjectEx)
version = item.Properties_.Item("Version").Value.ToString()
MessageBox.Show(String.Concat("QuickTime version: ", version), Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
Next
End If
Catch ex As Exception
MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If (Not Object.ReferenceEquals(item, Nothing)) Then Marshal.ReleaseComObject(item)
If (Not Object.ReferenceEquals(collection, Nothing)) Then Marshal.ReleaseComObject(collection)
If (Not Object.ReferenceEquals(service, Nothing)) Then Marshal.ReleaseComObject(service)
End Try
End Sub
<强>更新强>
在最新版本中,名称更改为QuickTime 7
。
因此您需要更改查询:
从Name = 'QuickTime'
到Name Like 'QuickTime%'
。