[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

detecting write protected media

Hi.
I need to detect whether media in floppy or MO disk is write-protected or not.
I've tried to determine it by opening device "\\.\A:" with GENERIC_WRITE access permission, but it succeeds even if the media is write protected.
Any ideas ?
Thank you in advance.
0
sisadmin
Asked:
sisadmin
1 Solution
 
DragonSlayerCommented:
I suppose you could try creating a file in it and see if it works:

HANDLE hTempFile;

GetTempFileName("A:\\", // dir. for temp. files
  "NEW",                // temp. filename prefix
  0,                    // create unique name
  szTempName);          // buffer for name

hTempFile = CreateFile((LPTSTR) szTempName,  // filename
  GENERIC_READ | GENERIC_WRITE, // open for read-write
  0,                            // do not share
  NULL,                         // no security
  CREATE_ALWAYS,                // overwrite existing file
  FILE_ATTRIBUTE_NORMAL,        // normal file
  NULL);                        // no attr. template

if (hTempFile == INVALID_HANDLE_VALUE) {
  printf("Read-only");
}


0
 
sisadminAuthor Commented:
Hi.
I suppose this will work fine for floppy, but this might be wrong on MO disk, that is NTFS formatted and can have protected folders and so on.
0
 
griesshCommented:
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and delete this question since nobody had a satisfying answer for you.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
ComTechCommented:
After review, the proposed answer will be accepted by:

ComTech
Community Support Admin
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now