Detecting USB Ports

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm looking for a way to detect available USB ports on a machine using VB
..NET. It would also be advantegous if I could tell if they had hardware
plugged into them as well.

Any help is appreciated,

Thanks,
Deab
 
Dean,

I have not done it for USB, but I have done it for COM ports and it works
well. You might be able to do something similar. Here is the code for COM
ports ( it is C# but should be easy to port to VB.NET):

RegistryKey comPortKey = Registry.LocalMachine.OpenSubKey(
"HARDWARE\\DEVICEMAP\\SERIALCOMM" );

string[] portNames = comPortKey.GetValueNames();

for( int x=0; x<portNames.Length; x++ )
{
string comPortValue = ( string )comPortKey.GetValue( portNames[ x ] );
comPorts.Add( comPortValue, comPortValue );
}

Hope that helps somewhat

-Robb
 
in vb.net:
Dim comPortKey As RegisTryKey =
RegisTry.LocalMachine.OpenSubKey("HARDWARE\\DEVICEMAP\\SERIALCOMM")

Dim portNames() As String = comPortKey.GetValueNames()

Dim x As Integer
For x = 0 To portNames.Length- 1 Step x + 1
Dim comPortValue As String = CType(comPortKey.GetValue(portNames( x
)), String)
comPorts.Add(comPortValue, comPortValue)
Next

regards,
 
Back
Top