How can I programmitcally Disable and Enable a USB device

I'm using a USB to Serial Converter (Moxa brand) box.  A few times a week this box locks up.  To reset the box, I can reboot the computer, or unplug the box, or Disable/Enable USB device in device manager.   I'm probably eventually going to replace the converter box with a conventional RS232 Serial board.  In the meantime, I think there must be a way to programmitically Disable and then Enable this USB device.
dve01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinnyd79Commented:
Maybe you can call some command line utilities from vb. Maybe devcon or deveject.

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272

http://www.jsifaq.com/SUBQ/tip8400/rh8496.htm


I tried using deveject from vb to eject a USB drive so it can be safely removed.
I put deveject in my system32 folder and then used:


Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400

Private Function ShellWait(PathName, Optional WindowStyle As VbAppWinStyle = vbNormalFocus) As Double
Dim hProcess As Long, RetVal As Long
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(PathName, WindowStyle))
    Do
        GetExitCodeProcess hProcess, RetVal
        DoEvents: Sleep 100
    Loop While RetVal = STILL_ACTIVE
End Function

Private Sub Command1_Click()
 ShellWait Environ("ComSpec") & " /c deveject -EjectName:" & Chr$(34) & "USB Mass Storage Device" & Chr$(34) & " > C:\Temp.txt", vbHide
Dim ff As Integer
ff = FreeFile

' display results
Open "C:\Temp.txt" For Input As #ff
fData = Input$(LOF(ff), ff)
Close #ff
MsgBox fData
Kill "C:\Temp.txt"
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dve01Author Commented:
I tried Devcon and shelled out from project.  Seems to work pretty good
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.