471,339 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

Detecting USB Ports

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

Jul 22 '05 #1
2 2501
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
Jul 22 '05 #2
in vb.net:
Dim comPortKey As RegisTryKey =
RegisTry.LocalMachine.OpenSubKey("HARDWARE\\DEVICE MAP\\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,

Robb Gilmore wrote:
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

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jive | last post: by
reply views Thread by pothik05 | last post: by
2 posts views Thread by Hemant Shah | last post: by
3 posts views Thread by andyI | last post: by
2 posts views Thread by Dean | last post: by
1 post views Thread by henrycortezwu | last post: by
2 posts views Thread by joaquimfpinto | last post: by
3 posts views Thread by =?Utf-8?B?Vmlua2k=?= | last post: by
10 posts views Thread by sklett | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.