Language: VB.NET
No Title
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
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

