Jump to content

Restarting a USB device


ChrisL
 Share

Recommended Posts

What I want to do is to restart a stopped USB device.

The thing is that a USB card reader occasionally drops out and the drive letters dissapear.

What I would like to do is to be able to restart the device, or force windows to rescan the hardware.

If I stop the device manually I have this status in device manager....

Windows cannot use this hardware device because it has been prepared for "safe removal", but it has not been removed from the computer.

Telling device manager to rescan for devices doesn't work.

Do any of you clever people know of a call that can be made to force windows to restart the device?

Thanks

Link to comment
Share on other sites

I gave up on setupapi.dll + GUID + PVOID hell... This can be done without devcon.exe if you are brave enough to learn setupapi.dll.

Lar.

Well thanks for looking..

This is what I have so far using Devcon which seems to work OK

Fileinstall ("Devcon.exe", @tempdir & "\Devcon.exe",1)

$iniFile = "DriveMonitor.ini"

$DriveList= IniReadSection($iniFile,"MonitorDrives") 

While 1
    If NOT DrivesAreOK() then   
        RunWait (@tempdir & "\Devcon restart USB\ROOT*", @tempdir, @sw_hide)
    EndIf
    
    Sleep (1000 * 60);checks once a minute
WEnd

Func DrivesAreOK()
    Local $dOK = 1
    For $i = 1 to Ubound ($DriveList) -1
        If DriveStatus($DriveList[$i][1] & ":") = "INVALID" then $dOK = 0
    Next
    Return $dOK 
EndFunc

The ini file looks like this

[MonitorDrives]
1=F
2=G
3=H
4=I
5=J
6=K
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...