Solved

detecting write protected media

Posted on 2001-08-02
4
225 Views
Last Modified: 2010-04-02
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
Comment
Question by:sisadmin
4 Comments
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6344878
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
 
LVL 1

Author Comment

by:sisadmin
ID: 6352760
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
 
LVL 11

Expert Comment

by:griessh
ID: 6842561
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
 

Accepted Solution

by:
ComTech earned 0 total points
ID: 6858039
After review, the proposed answer will be accepted by:

ComTech
Community Support Admin
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question