Archived

This topic is now archived and is closed to further replies.

How to detect if running from unwritable drive

This topic is 5219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, What API Calls should I google for, dealing with the detection that my app is running from the a CD or any other type of unwritable medium (like a locked floppy, or a locked USB disk), so that I don''t write logs, etc to the medium, which would cause a failure? Thanks for any help on this...
[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]
"I say we take off and nuke the entire site from orbit. It''s the only way to be sure."

Share on other sites
Try to create a file. If it fails, you don''t have write access

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

Share on other sites
How about trying to open a file with write mode; if it fails, you can pretty much assume the drive is unwritable.

Otherwise check out the MSDN focuments for File I/O

Share on other sites
try to open a file and if it fails ?
maybe the user just doesnt have permissions on that computer to create new files ?

"A soldier is a part of the 1% of the population that keeps the other 99% free" - Lt. Colonel Todd, 1/38th Infantry, Ft. Benning, GA

Share on other sites
quote:
Original post by ncsu121978
try to open a file and if it fails ?
maybe the user just doesnt have permissions on that computer to create new files ?

Which is, in practice, not different from running of an "unwritable medium". It is easier to directly check for the inability to write (which is what the OP wants to check for, by the way), than to try and cover all the possible reasons why writing might fail.

Share on other sites
To get the drive that the program is running off of:
char chDriveLetterGetModuleFileName(GetModuleHandle(NULL),&chDriveLetter,1);

And theres GetDriveType to see what type of drive it is

• 22
• 10
• 19
• 10
• 14