Debasish Das Gupta
Debasish Das Gupta

Reputation: 109

How to detect gsm modem using vb.net

I am a newbee in vb.net. Want to know how to get port of a connected gsm modem programmatically using vb.net

Dim MgmtSearch As ManagementObjectSearcher

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    For Each queryObj As ManagementObject In MgmtSearch.Get()
        If queryObj("Status") = "OK" Then
            ListBox1.Items.Add(queryObj("Description"))
        End If
    Next
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    MgmtSearch = New ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_POTSModem ")
End Sub

The above code I am using but getting An unhandled exception of type 'System.NullReferenceException' occurred in Serial Port Project.exe error when clicking button.

I am using Dlink Modem and vb.net 2015

Upvotes: 0

Views: 946

Answers (1)

FloatingKiwi
FloatingKiwi

Reputation: 4506

This line is failing on my machine with an "Invalid Parameters" exception:

MgmtSearch = New ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_POTSModem ")

This is due to the double slash replace it with "root\CIMV2" instead and it will start working.

I'm not sure how the form continued to load after this exception occurred but the result is that MgmtSearch is null.

Upvotes: 1

Related Questions