Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Detect USB Device

I'm trying to write a small utility which will run in the system tray and detect when a particular USB device is plugged in, and then get it to launch a program.

Is this possible with Visual Basic 6.0 SP5?

Specifically, I want to be able to detect when the Hauppauge DEC2000-t is plugged in (identify it either by it's name or DeviceID) and then launch a program (ShowShifter).


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Detect A USB Device?
Hi guys

Im trying to write the code for my VB program that detects a USB device, in this case a USB camera, does anyone have any suggestions? tips or what have ya

Thanks for answering, much appreciated

Detect Attached Device
Hey all,

I am programming a project that includes several handheld scanners (pocket pc driven) and several client computers (windows xp). There will be files thrown around between the pcs and the handhelds during normal execution of the program.

My problem is I need to be able to detect the device before I attempt to connect to it. I am using CeRapiInit to initiate the connection, but, if there is no device connected, it just hangs and does not recover. I could use this to also check for the device before sending files to it, not just at the start of the program. This would allow the users to start the program with or without the handheld in its cradle or to connect it at a later time while running the program.

If anyone could help me to detect the device it would save my project.

Bob F.

Mscomm-detect The Device
i think mscomm. isn't a interesting topic!!!!!!!

Detect From The Different Input Device
pls help.
i have a problem with the barcode scanner & keyboard.
in VB6, can i detect which one input from barcode scanner & which one from the keyboard.

thanks for attn.

Detect Which Device Has Been Unplugged
Hi everyone !

My app would like to be aware of any device unplug/disconnection, be it USB or COM or PS2, etc.

So when I unplug, for instance, my mouse, a MsgBox raises: "You unplugged the device Genius Standard PS2 Mouse".

I would appreciate any approach. Thank you !!!

How To Detect A Device Attached On USB With VB Code?

How v can detect any device which is being attached with USB Port of the system, with VB code? I want to write a program which can detect any deivce as that is attached with USB.

Any Help or hint.


Asad Ijaz

" ...You may be disappointed if you fail, but you are doomed if you don’t try. "

Detect Whether The External Device Is Connected To Com Port 1 Or 2

I have connected an external device to commport1 and I have written Mscomm1.Commport=1 in VB 6.0 and I was able to pass the data to the device and receive acknowledgement.
In case if I connect the device to commport 2 I have to change my code to Mscomm1.Commport=2 . instead can I identify to which comm port the external device is connected and change dynamically.
Can someone help me.


Getting Device List From Device Manager With Setupapi
I had need to figure out which COM port a USB-serial converter was installed as. If you looked under Device Manager, it was easy to tell from the names. First I tried EnumPorts, but that just gave me the COM number and 'Local Port'. I tried using the WMI, but the device I was looking for was the one that it wouldn't list for some reason. (Worked fine for my other virtual COM port USB device.) So I stumbled onto the setupapi library, but there was no VB examples, only some C. So through some trial and error, I devised a DeviceLister VB6 class to get names and descriptions of devices. It could be changed to include more, but I stopped at names/descriptions.

By five-cent example returns a list of 'Ports' devices (your results will vary):
ECP Printer Port (LPT1)
Communications Port (COM1)
Digi PKG-U Serial Port Adapter (COM16)
^-that last one was the sucker I was after

I thought 'Hey I wonder if anyone else would be looking for this?' so I post it here. It's not the prettiest implementation, but might be a starting point for someone.

Note: The MSDN seems to indicate that this only works for Win2k and beyond.

EDIT: I added an example of retrieving all devices. Also I setup an option to list devices that are not present. Now I can see ports that were installed but aren't active.

Edited by - FD 80 on 6/20/2008 11:35:57 AM

Uninstall A Device From Device Manager.
Hi all,
Is there a way to uninstall a device in device manager with vb6?

I've run into a rootkit that I am trying to make a tool of mine remove. I've tried simply stopping the service but this can cause BSOD's which we all know are fun in windows.

As always any help is appreciated,


Detect SMTP Server And Detect E-mailaddresses From My MSN Messenger Contactlist.
does anybody know how I can make a program that automaticaly sends an e-mail to my full msn list ...

I allready know how to send E-mails ...

But I don't know yet how to get a list of all the e-mailadresses of your msn messenger contactlist.

And I also have a problem with automatically detecting the SMTP-server. (If I want to E-mail something using Visual Basic ... I always need to set my SMTP-server and I don't like that anymore. There should be a way to automatically detecting it)

Device Context VS Memory Device Context?
Hi. In my spare time ive been reading some sttuff on windows graphics programming
and it seems to be an important topic that of the DeviceContexts, well, what
i have read says that the DC is an object that let me work with devices like
printers, windows (((how is it a window is a device??))). Ok it is like a VB object
but what about the Printer object or the Screen object is that the same?
Also, i read about memory device contexts too, and that i really dont understand it...
im not saying go into deep explanation but what is the difference between MDC and DC... and do i need to worry about it?

Usb Gps Device

i recently bougth a gps receiver, and i want to access to it via vb. my gps starts recording points on its memory, and when i plug it it has a type "A" connector (USB) in the gps software retreives the points and exports them to google earth, the gps software is pretty bad it doesnt offer you many options so i am planning on making my own gps software, the problem is i dont know how to access the USB device. i supose that if i can acces the gps memory, i can retrieve all the data of the points, thanks.

Mp3's Mci Device
what mci device do i use for a mp3....

Hwo Can I Know Whether A Device Is In Using Or Not
help me,please.I don't know how to detect a touch-screen device,not printer or monitor.and I don't have the driver interfaces

Run .chm From Any Cd-rom Device?
Hi guys

I am trying to make my program run a .chm (compiled help file) from the program's working directory (ie the cd rom) but it is not loading. If i change the code to tell the program to find the .chm from the e: (my second cd rom device), it will run.

Can you programme it so it loads from the current working directory, without having to specify the path?

Here is my code:

Private Sub cmdHelp_Click()
Set wShell = CreateObject("Shell.Application")
wShell.Open "e:Help.chm"
End Sub

This code works fine, but if i delete the "e:", it doesn't find it.
I want this code to work across all (cd rom) drives, not just e:

Cheers - Diver.

CD/DVD-ROM Device Name
help me please with read CD/DVD-ROM device name and device-letter (E:).

For i = 0 To 2
For c = 0 To 1
If getstring(HKEY_LOCAL_MACHINE, "hardwaredevicemapscsiScsi Port " & i & "Scsi Bus 0Target Id " & c & "Logical Unit Id 0", "type") = "CdRomPeripheral" Then
Combo1.AddItem getstring(HKEY_LOCAL_MACHINE, "hardwaredevicemapscsiScsi Port " & i & "Scsi Bus 0Target Id " & c & "Logical Unit Id 0", "Identifier")

Debug.Print vbCrLf & getstring(HKEY_LOCAL_MACHINE, "hardwaredevicemapscsiScsi Port " & i & "Scsi Bus 0Target Id " & c & "Logical Unit Id 0", "Identifier")
End If
Next c
Next i

with this I get name of CD/DVD device but I need know device-letter (E:) of every d evice.

I have E: (DVD-ROM: TOSHIBA DVD-ROM SD-M1612) and F: (TEAC CD-W540E) and I need this get with my program.

Help me please.

USB Device
I am trying to build a USB connected device.
I want to use the USB HID mode. my hardware will be 3 binary switch closures. No Output at all, just inputs.

Any ideas on how to get this to work on the software side?

I was hoping to use a standard windows driver so that it would be easier to install and I would not have to write the driver then!

thanks. if you have USB design experience I would love to hear from you. google does not seem to have much in the way of technical documents. A lot of sites selling USB services.

Name Of USB Device
I basically need to know how to get the name of the device attatched to each usb port. Like when you plug something in and windows pops up and knows exactaly what it is (sometimes lol).

I can view all of the properties such as IRQs and junk , but I want to be able to say usb port one and click a button and have it say something like "Logitech MX 1000", etc, etc.


What I actually need this for: I have a Com port hub (4 com ports connected to laptop through usb). Windows detects them as Com Ports, but "Com Port 1" is stamped beside the port on hub and windows assigns it a random Com Port. This gets confusing and is a real pain when programming.
I have a device (camera) on "Com port 2" of hub and windows calls it com port 5. So I tell my app that com port 5 is camera, but when i unplug the hub from laptop and plug it back in, it will not be com port 5 anymore so my program does not work. I will always have the camera plugged into "Com Port 2" on the hub, but I need the above to figure out what logical port (windows) it is hooked up to. So I can say whats on logical Com Port 7? Ah Camera and set this in my program.

Kinda confusing, but thanks in advance for your help!

Use An Usb Device With Vb Help
I have an usb device and windows xp and the drivers that comes with the usb device doesn't work with win xp.
i would like to know if i can make a vb program that can comunicate with this device.
Thanks for any help.

Getting A Device ID?
Declare Function mciGetDeviceID Lib "winmm.dll" Alias "mciGetDeviceIDA" (ByVal lpstrName As String) As Long

Does anyone how to use the above function?? I am not sure what to put for lpstrName! Can anyone give some examples?

Getting A Device Name (VB6)

Does anyone know how to get a hardware device name + description usingVB6?

For example, i have a third party serial COM port installed in my PCwhich is listed as something else other
than the standard "Communications Port (COMx)" in device manager... howdo i obtain this listed description?


USB Device

i have a fingerprint device, and i need to access it from within VB ( iam not planing to use the product SDK ) i need a hint on how to check a USB device from VB


EVB On An CE.NET 4.2 Device

I have an old PocketPC application written in eVB that I need to install on a PSC Falcon 4220 running CE.NET 4.2.
But when I try to run it gives me this error message: "Application error Cannot find extension file Forms Data. Pleas run setup to restore this file."
Even the simplest "Hello world" application won't run!

On a message board elsewhere I found a message of someone saying eVB is not supported on CE.NET 4.2.
Is this really true? Is there any other way to make an eVB application work on a CE.NET 4.2 device or do I have to buy a very expensive Visual Studio .NET licence and rewrite the whole application in .NET !?!?


USB Device
How can I send a win32 command to a USB device?23

PCI Device List
Hi all,

I have a problem thats not Xtreme and not really VB.

I need to create a list of PCI devices installed in an XP system using Delphi. If anybody has any ideas on where to find the information that could be used to create such a list then please let me know. I'm certain the relevant information must be stored in the Registry somewhere.

I'm certain it isnt that hard and definatley not 'Xtreme', but so far nobody can point to where that info is stored.


What's A Device Context?

I'm trying to make a semi-transparent textbox. And I want a background image on it, so I am trying to understand this tutorial:

But It keeps talking about a DC, which is device context.

What is it?

And how to I link a class (or even make one???) and link it to a textbox??

Please help!

Thank you!

(cause I dunno the first thing about this)

Connecting To A Device, Need Some Help
Hello, I have created a device, but have som problem accessing the "IRP",

this is the Code I used to create the IRP file:

const WCHAR deviceNameBuffer[] = L"\Device\MyDevice2";
PDEVICE_OBJECT g_RootkitDevice;

nRet =IoCreateDevice (DrvObj, sizeof(65533), &deviceName, 0x00000022, 0, TRUE, &g_RootkitDevice);

if (NT_SUCCESS(nRet)) {
DbgPrint("IoCreateDevice Succeded.");
} else if (NT_INFORMATION(nRet)) {
DbgPrint("IoCreateDevice returned Information");
} else if (NT_WARNING(nRet)) {
DbgPrint("IoCreateDevice returned Warning");
} else if (NT_ERROR(nRet)) {
DbgPrint("IoCreateDevice returned error");
", nRet);
and this is the code I use in vb6 to access the file created...
(btw I know the file is created because "IoCreateDevice Succeeded" return to DbgView)

Private Sub Form_Load()
Open "\DeviceMyDevice2" For Binary As #1
Close #1
End Sub
The function fails with the error code 76, "Path not found", any idea why?

So What Actually Is A Device Context?
Can someone explain precisely what the terms device context, bitmap and handle mean, and how they relate to each other?

The background is, I'm trying to find the "best" way to load a bitmap file into memory and then blit it to a buffer and ultimately to a Form or PictureBox. I've used BitBlt before, but I've only really copied examples and haven't properly understood what is going on. I've read loads of things like "Select the bitmap into the DC" but don't really understand them fully.

DX8 Device Units

This question could have been asked before, but I could not find the answer (not even in DX8 documentation).

When you specify a position for a vector, in what units do you do that? (meaning much like ScaleMode property in VB). Is there any way to change these units? If no, then is there any way to convert between them and standard measurment units (English and International)?

Let's say I want to draw a 30 meter landscape or a 41 feet landscape, or a square of 1 feet 25 inches. What do I specify for the coordinates?


USB - Device Names

I'm trying to connect to USB devices using code below, but are unsure how the HID.dll presents the device names. If I try 'Device Manager' and use the names under USB controllers, these names are not recognised. Ultimately I will be communicating with a GPS unit, and will not be going down the mscomm32 path due to licensing restrictions.


Public Function OpenUSBdevice(NameOfDevice$) As Boolean
' This function searches the system HID tables for NameOfDevice$
' If found then it opens the device and returns TRUE, else it returns FALSE
Dim HidGuid As Guid
Dim Success As Boolean
Dim Openned As Boolean
Dim Buffer(256) As Byte
Dim DeviceInterfaceData As Device_Interface_Data
Dim FunctionClassDeviceData As Device_Interface_Detail

' First, get the HID class identifier
Call HidD_GetHidGuid(HidGuid.Data(0))
' Get a handle for the Plug and Play node, request currently active HID devices
PnPHandle& = SetupDiGetClassDevs(HidGuid.Data(0), 0, 0, &H12)
If (PnPHandle& = -1) Then ErrorExit ("Could not attach to PnP node")

HidEntry& = 0
Openned = False
DeviceInterfaceData.cbsize = 28 'Length of data structure in bytes

' Look through the table of HID devices
Do While SetupDiEnumDeviceInterfaces(PnPHandle&, 0, HidGuid.Data(0), HidEntry&, DeviceInterfaceData.cbsize)
' There is a device here, get it's name
FunctionClassDeviceData.cbsize = 5
Success = SetupDiGetDeviceInterfaceDetail(PnPHandle&, DeviceInterfaceData.cbsize, _
FunctionClassDeviceData.cbsize, UBound(FunctionClassDeviceData.DataPath), BytesReturned&, 0)
If (Success = 0) Then ErrorExit ("Could not get the name of this HID device")

' Convert returned C string to Visual Basic String
HidName$ = Empty
i& = 0
Do While FunctionClassDeviceData.DataPath(i&) <> 0
HidName$ = HidName$ & Chr$(FunctionClassDeviceData.DataPath(i&)): i& = i& + 1

' Can now open this HID device
HidHandle& = CreateFile(HidName$, &HC0000000, 3, 0, 3, 0, 0)
If (HidHandle = -1) Then ErrorExit ("Could not open HID device")

' Is it OUR HID device?
If HidD_GetProductString(HidHandle&, AddressFor(Buffer(0)), UBound(Buffer)) Then
DeviceName$ = Empty
i& = 0
Do While Buffer(i&) <> 0: DeviceName$ = DeviceName$ & Chr$(Buffer(i&))
i& = i& + 2
If (StrComp(DeviceName$, NameOfDevice$) = 0) Then
Openned = True
Exit Do
End If
End If 'HidD_GetProductString
Call CloseHandle(HidHandle&) ' Was not OUR HID device
HidEntry& = HidEntry& + 1 ' Check next entry
Loop 'SetupDiEnumDeviceInterfaces returns FALSE when there are no more entries

OpenUSBdevice = Openned

End Function

thanks in advance


Connection To USB Device
Hallo Hi everybody,
I want to make a connection to USB device ( card reader ) in order the user to log in to my system. I'm using vb6. Is there anyone could help me how vb6 to communicate to the device?.


Device Caps
Using DirectX 7..

I need some help figuring out what caps is needed by the D3D Device to do the following states:

'Enable alpha-blending

'Set Blend State

'Set Alpha Blend Operation
I use Triangle strips and lists on Transformed and Lit vertexes.

The textures are created for hardware with:

'Set Texture Description
TempDescription.ddsCaps.lCaps = DDSCAPS_TEXTURE
TempDescription.ddsCaps.lCaps2 = DDSCAPS2_TEXTUREMANAGE
And for software with just:

'Set Texture Description
TempDescription.ddsCaps.lCaps = DDSCAPS_TEXTURE
Any suggestions or links that might help?

Connection Through IR Device
Hello guys,

I have an IR Device installed on my computer and I'd like to make a program in order to be able to send and recieve data from / to a cell phone connected through this IR device. Does anyone know something about this?

Thank you Tassos.

Device Lost Again
Hi. In my Fullscreen app's Render sub, I use this code:

dim hR as long

hR = g_d3ddevice.testcooperativelevel()

if hR = D3DERR_DeviceNotReset Then

g_d3ddevice.reset g_d3dpp

elseif hR <> 0 then

exit sub

end if

Call DoRender

End Sub

I'm sure g_d3dpp is all set, but if I use this code, the screen starts flickering after I pressed <CTRL>+<ESC> or <ALT>+<TAB>.


Help In Enabling Device
hi all
plz i tired from try enable or desable sound card from VB is any one know how to do that ..
and thanks

Remove An USB Device Via Vb.
Hi to all. is there a method to remove an usb device? Such as Windows' "Remove" command from My Computer.

thanks to all

USB Device Permissions
Here is my situation.
I am creating a program that is gong to turn a computer into a public kiosk. And the purpose of the kiosk is to download specific files onto a USB pen drive device.

The problem is that if the user inserted some device such as a keyboard then the computer security would be compromised. So what I need is for the program to detect devices inserted into the USB port and then either accept or reject them.

I realize that I may have to accept or reject a device based upon the devices name and save a list of accepted devices which is acceptable. But I can not have the computer at risk of compromise.

My searches on Google and this forum did not turn anything up that really helped me.

Device Unavailible
hi there. i have forgotton the code for this and hope you can help me out:

Private Sub Dir1_Change()
Dir1 = drvMain.Drive 'ERROR happens here when we change the folder when pointing at current unavailible device
File1.Path = Dir1.Path
End Sub
Private Sub drvMain_Change()

Dim errormsg As String
On Error GoTo driveerr
drvMain = drvMain.Drive

If Err.Number = 68 Then
errormsg = MsgBox("The drive chosen is not ready or is unavailible. Please try again", vbCritical, "Drive unavailible")
Exit Sub
End If
End Sub

error happens when the drive is unavailible so when you try and change it, the error comes up in VB

Disable Device
Hello I am new to vb. I am writing a small scipt that will allow me to change ip addresses on my wireless NIC for my laptop. So far everything is going good except onething. Is there a way to disable/enable the NIC in vb(5.0) ??? So that the new address would take affect.

Device Context Help!
Identifies the device context.

Where would I find a list of all of them?

Device Type
hi i want to use the mmcontrol with my project. I has to be able to play mp3's i have already got the mmcontrol to play cd's but how would i make it play mp3's, do i need to use a specific device type?

Device Context
Hi, great job with the forums.I have been registered under a different account that I lost, for about 2 years now, and I have to admint I enjoy the searching facilities of the forums very much.I'm quite confused now, so any help greatly appreciated!

I'm making an application where the user initially loads an image using a CommonFileDialog box.Creating a DC I can paint this onto a picture control. Then the user using his mouse is clicking on the image to select the area he is interested in and I have it displayed onto the picture alone,then he can zoom it e.t.c. register control points e.t.c.
My problem is that once I have the selection I store everything into arrays and manipulate the pixels or their centers the user then will load another image.In the meantime when I ask to Get the pixel value let's say when the user has selected a region and I display it on the picture control alone, it isn't actually reading what is beeing displayed on the only does so when the image is loaded and remains intact.
I need to be able to update Device Context since I read the values using for example API calls like this one:

greyValue = GetPixel(lngDC, MousePixelPositionX, MousePixelPositionY) And &HFF

My problem is that let's say the picture shows a 20 x 20 face that the user selected and I have the rest all white.When I read the values though with the mouse movement, it will show all the positions, even in the selected area displayed on the picture, as 255 ( white in greyscale)
which means Im doing something wrong.

Part of the code within a sub i use to store the selection:

'trying to debug Device Context problem cause final output still displays orginal BMP transparent background or DC is not updated of the current display on screen

Set Picture1.Picture = LoadPicture ' clear its contents
Set stdPic = LoadPicture

'show selection
Call Array2Picture(1) 'ingore this bit,displays the array back to picture
ProgressBar1.Visible = False
statusText = "Ready"
Label9.Caption = statusText
ProgressBar1.Value = 0

'DC once I have new content i though I would update the DC like this
lngDC = CreateCompatibleDC(Picture1.hdc)
lngOrigBMP = SelectObject(lngDC, stdPic.Handle)'this is used when loading the original BMP too

Anyways, If I'm confusing you guys too much, i just need to know how to pass the current contents of a picture to a DC.
I imagine that I can't also pass arrays to DC directly.
Erm, I'm confused

Device To Draw On? (HDC)
I found this function that is exaclty what im looking for, however one of the parameteres says the input is a "Device to Draw on" As Type Long. How would I go about getting an object as this decive sush as Form1.

' DrawGradient (FUNCTION)
' This function is used to draw gradients with four colours
' Arguments:
' hDC - The device to draw on
' Top - Distance in pixels, from top
' Left - Distance in pixels, from left
' Width - In pixels
' Height - In pixels
' colourTopLeft - The colour of the top-left corner
' colourTopRight - The colour of the top-right corner
' colourBottomLeft - The colour of the bottom-left corner
' colourBottomRight - The colour of the bottom-right corner
Public Function DrawGradient(hDC As Long, Left As Long, Top As Long, Width As Long, Height As Long, colourTopLeft As Long, colourTopRight As Long, colourBottomLeft As Long, colourBottomRight As Long)


End Function

...could Not Connect To The Device....
Hi all !

I am trying now for 3 days to program my "typhoon myguide pocket pc" with embedded visual basic, without any success : if VB tries to connect to the pocket pc, I get :
The platform manager could not connect to the device.
This happens if the
project type does not match to the connected device,
or if a required file in
Windows CE Services or the platform SDK is missing or corrupt.
(Error code=0xLX)

The connection (active sync) is working, I can easily transfer files to the pocket pc.
The selected platform in embVB is Pocket PC 2002 (Default Device), my Pocket PC uses Microsoft Pocket PC, Version 4.20.1081.
I dont use any german pathnames (a known bug of embedded VB, which I found on the MS homepage).
Is there anyone, who had the same problem and solved it ????
I would be glad, if someone could help me !!!

thanks, Joerg

Device List
Is there way to display the Hardware devices in the VB ? (Getting the device list) ?

Thanks in Advance

About Device Contexts
I have been experimenting with using device contexts (DC) with various api routines. Once i get the DC of a window I want to do something with, whether it is copying some part of it with bitblt, or getting the color of a pixel, it seems that I must activate the window and bring it to the front before the routine will work. Why is this required? Is there a way around this? I would think if i got the dc of something i could just copy some pixels from its window without haveing to bring it to the front.

Device Interface
How can we use device interface via 'SetupDiGetClassDevs' api function.
I am unable to find device interface class guid?

At Device Start
hi. i was wondering if there was a way to maybe use the login dialog or some way in vbtocreat a log in screen so that when someone moves to open a usb or drive the vb program comes up to ask for a password to enter.

also i was wondering if such a program cood be used automatcially from the usb thing..

is this possible? please help

Device Context Help
I have a program right now that looks at another program and searches for a particular child window. This window is like a status bar and is constantly changing it's color from green, yellow to red. I have the prgram so far where is goes and captures the window and gets the Device Context handle.

My question is, how do I go about getting the color that is being painted by the Device Content. I want to check the color and do certain thing based on the color.

I appreciate any help on this


Copyright 2005-08, All rights reserved