Solved

detecting write protected media

Posted on 2001-08-02
4
222 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now