Search code examples
c#winapiusbserial-portdevice-driver

RASEnumDevices with Port name?


I enumerated the RAS capable devices using "RasEnumDevices" and I am getting the DeviceName as "Communications cable between two computers #8","Communications cable between two computers #7" etc., And my friendly name of the device looks different as "USB Device (COM10)" , I got it through SetupDiGetDeviceRegistryProperty.

Is this the normal behaviour? Because When I try to create a Rasphonebook, I cant Identify my connected device name. Is there a way to make both device name and friendly name same?

I tried enumerating "RasEnumDevices" but am getting list of devices.

WAN Miniport (L2TP)
WAN Miniport (L2TP)
WAN Miniport (PPTP)
WAN Miniport (PPTP)
WAN Miniport (PPPOE)
Communications cable between two computers #14
Communications cable between two computers #13

How to choose my device from the above list?

or Any Apis available only to list the connected RAS devices?

or Any APIS to get only the connected device name? like "Communications cable between two computers #8" in my case..

Update :

RAS devices

In the above picture I can see the RAS device name with COM port name. Is there a way to enumerate these devices with COM port name?


Solution

  • Unfortunately what you're seeing come back from RasEnumDevices is exactly what's expected. There is no way to directly tie a RASDEVINFO structure back to the actual hardware, or what port it's assigned to since the structure really doesn't give you any way of uniquely identifying the hardware.

    Say you have two PPTP VPN ports, you can't distinguish port 1 from port 2... they'll both come back from the API call as "WAN Miniport (PPTP)".

    By the way, if you don't want to deal with the interop code yourself you may want to check out the DotRas SDK on CodePlex, it has pretty much the entire RAS API wrapped.

    using DotRas;
    
    IEnumerable<RasDevice> devices = RasDevice.GetDevices();
    

    That's the call you'd have made to get the devices listed from RasEnumDevices using the above mentioned SDK.

    Here's a link for it if you want it: http://dotras.codeplex.com

    Edit: I wanted to add, your phonebook entry would only need to have the name of "Communications cable between two computers #14" because it knows which COM port it's associated with. You don't need to identify that yourself, nor would the entry work if you appended the COM port information to the device name.

    Good luck!