• Advertisement

Archived

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

How to detect if running from unwritable drive

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

If you intended to correct an error in the post then please contact us.

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... Jester Says: Visit Positronic Dreams!
[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
"I say we take off and nuke the entire site from orbit. It''s the only way to be sure."

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
OK, let me put in another form: how do i detect the system''s drives, their properties, and the one my program is running of?

Jester Says: Visit Positronic Dreams!
[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
"I say we take off and nuke the entire site from orbit. It''s the only way to be sure."

Share this post


Link to post
Share on other sites
To get the drive that the program is running off of:

char chDriveLetter
GetModuleFileName(GetModuleHandle(NULL),&chDriveLetter,1);


And theres GetDriveType to see what type of drive it is

Share this post


Link to post
Share on other sites

  • Advertisement