CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: VB.NET

No Title

123 Views
Copy Code Show/Hide Line Numbers
Public Shared Function GetPortNames(ByVal ItemName As String) As String()
        Dim localMachine As RegistryKey = Nothing
        Dim key2 As RegistryKey = Nothing
        Dim strArray As String() = Nothing
        Dim reg As New RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM")
        reg.Assert()
        Try
tryAgain:   localMachine = Registry.LocalMachine
            key2 = localMachine.OpenSubKey("HARDWARE\DEVICEMAP\SERIALCOMM", False)
            If (Not key2 Is Nothing) Then
                Dim valueNames As String() = key2.GetValueNames
                For i As Integer = 0 To valueNames.Length - 1
                    If InStr(valueNames(i), ItemName) > 0 Then
                        If strArray Is Nothing Then
                            ReDim Preserve strArray(0)
                        Else
                            ReDim Preserve strArray(strArray.Length)
                        End If
                        strArray(strArray.Length - 1) = CStr(key2.GetValue(valueNames(i)))
                    End If
                Next
            End If
        Catch ex As IO.IOException When TypeOf ex Is IO.IOException
            GoTo tryAgain
        Finally
            If (Not localMachine Is Nothing) Then
                localMachine.Close()
            End If
            If (Not key2 Is Nothing) Then
                key2.Close()
            End If
            CodeAccessPermission.RevertAssert()
        End Try
        If (strArray Is Nothing) Then
            strArray = New String(0 - 1) {}
        End If
        Return strArray
    End Function
by aronmek
  January 04, 2010 @ 12:51pm

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate