首先在项目中添加对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%'
。
这不适用于最新版本的quicktime。只是想知道他们有什么变化.. – Harsh
什么是确切的版本号? –
@Harsh你是对的,请看我的编辑。 –