USB Write Protected

psycho-j

New member
Joined
Jan 5, 2008
Messages
1
Programming Experience
3-5
I have a service that labels a USB Device upon detection but cannot get it to stop trying to write when USB is "locked / write protected". This causes a system hang. I would love some help with this.

Thankx in advance
 
well I was guessing that in your code you had something like the following;
VB.NET:
Expand Collapse Copy
Try
     'code to write the file
Catch ex as IOException
     'this will happen if there is a lock on the file or if the file cannot be written for some other reason check the 'ex' variable for more info
End Try
As for detecting when a device is plugged in, a quick google search found the following;
http://www.thescripts.com/forum/thread348267.html
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=948315&SiteID=1
 
To expand on DiskJunky's post, the Try/Catch blocks can have multiple Catch statements.

VB.NET:
Expand Collapse Copy
Try
     'code to write the file
Catch exIO as IOException
     'this will happen if there is a lock on the file or if the file cannot be written for some other reason check the 'exIO' variable for more info

Catch ex As Exception
  'this will happen if there's a problem that's not an IOException and when you use multiple catch statements, always put this one last (as a fail safe)
End Try
 
Back
Top