Jaa


How to determine BITS version (VB.NET version)

Here's a VB version of the detection code that works (thanks to Jonathan Wanagel from PAG). The reason the one to one translation doesn't work is that VB tries to proactively instantiate the referenced types, instead of doing it lazily as C# does. So this modified version uses a couple of helper functions that delay the creation of the types until we need them.

Imports System.Runtime.InteropServices
Public Class BITSVersionHelper
'2.0
<ComImport(), Guid("6d18ad12-bde3-4393-b311-099c346e6df9")> _
Friend NotInheritable Class BITS2_0
End Class
'1.5
<ComImport(), Guid("f087771f-d74f-4c1a-bb8a-e16aca9124ea")> _
Friend NotInheritable Class BITS1_5
End Class
'1.0
<ComImport(), Guid("4991d34b-80a1-4291-83b6-3328366b9097")> _
Friend NotInheritable Class BITS1_0
End Class
Private Shared BITS10Installed As Boolean
Private Shared BITS15Installed As Boolean
Private Shared BITS20Installed As Boolean
Public Shared ReadOnly Property IsVersion10Installed() As Boolean
Get
Return BITS10Installed
End Get
End Property
Public Shared ReadOnly Property IsVersion15Installed() As Boolean
Get
Return BITS15Installed
End Get
End Property
Public Shared ReadOnly Property IsVersion20Installed() As Boolean
Get
Return BITS20Installed
End Get
End Property
Private Shared Sub TestBITS10()
Dim bits As BITS1_0 = New BITS1_0
End Sub
Private Shared Sub TestBITS15()
Dim bits As BITS1_5 = New BITS1_5
End Sub
Private Shared Sub TestBITS20()
Dim bits As BITS2_0 = New BITS2_0
End Sub
Shared Sub New()
Try
TestBITS10()
BITS10Installed = True
Catch
BITS10Installed = False
End Try
Try
TestBITS15()
BITS15Installed = True
Catch
BITS15Installed = False
End Try
Try
TestBITS20()
BITS20Installed = True
Catch
BITS20Installed = False
End Try
End Sub
Private Sub New()
End Sub
End Class