Tags:Microsoft, Windows XP, Professional 2002 SP2, Java / VBA
I must detect external drive types under Windows XP. The drives can be: USB HD USB Stick ZIP Drive HD (local) HD (external)
I have found the tool fsutils and the java class FileSystemView.getSystemTypeDescription here are the results: * medium | explorer (type) | fsutils fsinfo drivetype | FileSystemView.getSystemTypeDescription * --------------------------------------------------------------------------------------------------------------- * local HD | local medium | d: - internal drive | local medium * USB - HD | local medium | f: - internal drive | local medium * USB-Stick | removable medium | f: - removable drive | removable medium * ZIP (empty) | removable medium | f: - removable drive | java.io.FileNotFoundException * ZIP+medium | removable medium | f: - removable drive | removable medium
The problem is: - USB HD is detected as "local medium" and not as removable (external) drive - USB stick is detected as "removable medium" and not as external USB drive - ZIP drive an USEB drive are indistinguishable
I did it long ago: I spawn a small C++ program to do the job. More secure than JNI: crashes don't touch the JAVA program.
Just to give you an idea of the program:
/******************************************************************************/ /* CVmain() */ /* Decodes the command line and provides response for simple cases. */ /* All responses start with a single line containing "OK" or "ERR", */ /* optionally followed by output (refer to the "Ok" and "Err" macro's. */ /******************************************************************************/ int CVmain(int argc, char* argv[], char* envp[]) { Sy_MODULE("CVmain()") CString s; void ejectMedia(CString);
if(!command.CompareNoCase("version")) // Version { CString version = _sqr_0ID + 21;// Skip SCCS text. int index = version.Find("Main.cpp"); // Find filename.
Ok; if(index > 0) // Extract program and version only. { version = version.Left(index) + version.Mid(index + 8); } printf("%s\n", version); }
else if(!command.CompareNoCase("volumeList")) // List all drives. { volumeList(); .................... The output is captured by the JAVA program. ;JOOP!