How to get RasDevice (Modem) Port Number

Jul 10, 2010 at 10:11 AM

Hello everyone! Forgive my ignorance here please. I need help on how to get the com port number assigned to my device. DotRas is smart enough to pick my device (modem) when I supply just a part of the device name. I looked at the device object's properties to see if there's a way to get the port number but no luck.

Is there a way to get this please? Any suggestion/pointer will be appreciated.

Thanks.

Coordinator
Jul 11, 2010 at 5:21 AM

Unfortunately the RAS API does not provide a way to tie the device back to the hardware, so the project doesn't support it. I already have it as a work item, but as of right now nothing has been done other than research. I believe others have been using WMI to get at this information.

Here's a link to the work item if you're interested in following it: http://dotras.codeplex.com/workitem/10011

Jul 11, 2010 at 9:35 AM

Thanks Jeff! I'll try researching on the WMI option. If you have any example on that or a pointer to where I can get help, I'll appreciate.

Thanks once again.

Coordinator
Jul 12, 2010 at 1:04 AM

Not sure if this will help, but check out an old post on this discussion forum. They have some WMI sample code they posted, though I can't guarantee it'll work.

http://dotras.codeplex.com/Thread/View.aspx?ThreadId=81268

Jul 12, 2010 at 9:39 AM
Edited Jul 12, 2010 at 9:48 AM

What can I say! IT WORKS LIKE MARGIC!

    Public Property ConnPort() As String
        Get
            Dim PN As String = MPort
            Try
                Dim MyDevice As RasDevice = RasDevice.GetDeviceByName(DevName, RasDeviceType.Modem)
                If MyDevice IsNot Nothing Then
                    Dim ManObjSearch As New ManagementObjectSearcher("Select * from Win32_POTSModem")
                    Dim ManObjReturn As ManagementObjectCollection = ManObjSearch.Get
                    For Each ManObj As ManagementObject In ManObjReturn
                        If ManObj("Name").ToString = MyDevice.Name Then
                            PN = ManObj("AttachedTo").ToString
                            Exit For
                        End If
                    Next
                End If
            Catch ex As Exception

            End Try
            Return PN
        End Get
        Set(ByVal value As String)
            MPort = value
        End Set
    End Property

Thanks for saving me all the trouble and time. I really appreciate it.

Coordinator
Jul 12, 2010 at 7:54 PM

Not a problem, glad I could help. Happy coding!