2014-03-05 47 views
1

我需要以编程方式查找安装的quicktime版本。以前我正在检查注册表项HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall的quicktime。 但是在quicktime(7.5版)的最新更新中,它不起作用。如何查找quicktime版本

我发现这段代码在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 

请让我知道如何找到快速时间的版本。

回答

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%'

+0

这不适用于最新版本的quicktime。只是想知道他们有什么变化.. – Harsh

+0

什么是确切的版本号? –

+0

@Harsh你是对的,请看我的编辑。 –