USB Key lock switch checking

  • Thread starter Thread starter Matijaz
  • Start date Start date
M

Matijaz

Hello,
Is there any possible way to check USB Key connected through USB port to
WinCE 5.0 device against "lock" switch turned on (hardware read-only
protection)?
Best Regards
Matijaz
 
I would have thought trying to write a file to the key and catching any
exceptions would show its lock status. If an exception occurs then its
probably in readonly mode.
 
I'm sure you'll get *some* exception, but which one isn't clear to me...and,
of course, there are multiple other things (full), that would also cause
exceptions.

You might try, at least in CE 4.x and higher, getting the partition
information from the Storage Manager by calling GetParititionInfo. The
structure that is filled-in seems like it has a good spot to indicate if the
partition is read-only (PARTITION_ATTRIBUTE_READONLY). In this case, it
might even be more likely that the GetStoreInfo() call would return
STORAGE_DEVICE_FLAG_READONLY when the lock switch was on, but it might
return STORE_ATTRIBUTE_READONLY instead, too (!).

Paul T.
 
And of course we're assuming that all keys with locks will behave the same,
which is dangerous at best.

--
<ctacke/>
www.opennetcf.org/sdf
Winner of the 2004 Pocket PC Magazine Best Software award
 
U¿ytkownik "Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam
DOT com> napisa³ w wiadomo¶ci news:[email protected]...
I'm sure you'll get *some* exception, but which one isn't clear to me...and,
of course, there are multiple other things (full), that would also cause
exceptions.

Well sometimes you will get an exception and sometimes you won't even if you
call write function and usb key is write protected. This is strange
behaviour - maybe it is some kind of buffered (cached) writing?
You might try, at least in CE 4.x and higher, getting the partition
information from the Storage Manager by calling GetParititionInfo. The
structure that is filled-in seems like it has a good spot to indicate if the
partition is read-only (PARTITION_ATTRIBUTE_READONLY). In this case, it
might even be more likely that the GetStoreInfo() call would return
STORAGE_DEVICE_FLAG_READONLY when the lock switch was on, but it might
return STORE_ATTRIBUTE_READONLY instead, too (!).

How can I call this functions, by using P/Invoke? I'm working on a smart
device project depending on Compact Framework library only . I don't use
Platform Builder or OpenNetCF. The usb key is a cheap no name device
manufactured in some slave labour factory in China.

Rgds
Matijaz
 
Yes, you'll have to P/Invoke it.

Paul T.

Matijaz said:
U¿ytkownik "Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam
DOT com> napisa³ w wiadomo¶ci
I'm sure you'll get *some* exception, but which one isn't clear to me...and,
of course, there are multiple other things (full), that would also cause
exceptions.

Well sometimes you will get an exception and sometimes you won't even if
you
call write function and usb key is write protected. This is strange
behaviour - maybe it is some kind of buffered (cached) writing?
You might try, at least in CE 4.x and higher, getting the partition
information from the Storage Manager by calling GetParititionInfo. The
structure that is filled-in seems like it has a good spot to indicate if the
partition is read-only (PARTITION_ATTRIBUTE_READONLY). In this case, it
might even be more likely that the GetStoreInfo() call would return
STORAGE_DEVICE_FLAG_READONLY when the lock switch was on, but it might
return STORE_ATTRIBUTE_READONLY instead, too (!).

How can I call this functions, by using P/Invoke? I'm working on a smart
device project depending on Compact Framework library only . I don't use
Platform Builder or OpenNetCF. The usb key is a cheap no name device
manufactured in some slave labour factory in China.

Rgds
Matijaz
 
U¿ytkownik "Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam
DOT com> napisa³ w wiadomo¶ci news:[email protected]...
Yes, you'll have to P/Invoke it.

Paul T.
Well, would you be so kind and please tell me in which dll file can I find
them?

Matijaz
 
That's an excellent question. Unfortunately, I don't have an answer. It
looks, based on quite a bit of browsing around, like the API is actually
implemented in a static library, rather than a DLL...

Paul T.

Matijaz said:
U¿ytkownik "Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam
DOT com> napisa³ w wiadomo¶ci
Yes, you'll have to P/Invoke it.

Paul T.
Well, would you be so kind and please tell me in which dll file can I find
them?

Matijaz
 
Back
Top