Solved

write-protected media error

Posted on 2004-08-12
7
400 Views
Last Modified: 2008-02-01
Hi all,

Is there a way to detect programmatically if a media is write-protected or not?
If this is impossible, is there a way to diable the dialog box that pops-up when i write/delete in write-protected media?

Im using C# and in my prog, when I do write functions (set attributes, delete, rename, etc) on files/directories in a write-protected media, i get a dialog box saying that the media is write-protected with cancel, retry and abort buttons.  I want to get rid of this thats why im asking the question above.

Thanks
0
Comment
Question by:3Mann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 11782938
Try creating a simple file on the media and writing something on it programmatically. If it fails - write protected.
0
 
LVL 1

Author Comment

by:3Mann
ID: 11783450
Yes, it fails.
I am able to catch an exception.  But i only am able to get the exception after the cancel, retry or abort dialog box is done.
How do i prevent the dialog box from appearing?
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 11783735
What if you get the DirectoryInfo for the root of the disk and check if it is ReadOnly (see the FileAttributes.ReadOnly flag)?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:3Mann
ID: 11784086
FileAttributes.ReadOnly checks only for the ReadOnly attribute of the file/directory.
Anyway, even if the media is write-protected, fileattribute returned for the root is Directory.

BTW, my media is SD memory card and SD reader/writer is connected via USB2.0 port.
0
 
LVL 1

Author Comment

by:3Mann
ID: 11939135
public bool isWriteProtected()
{
      bool bRet = false;
      uint uOrigErrMode = SetErrorMode(SEM_FAILCRITICALERRORS);

      try
      {
            //attempt to write to media
            string strTempDir = m_strDriveLetter + @"\forWPChk";
            Directory.CreateDirectory(strTempDir);
            if(Directory.Exists(strTempDir))
                  Directory.Delete(strTempDir);
      }
      catch(IOException)
      {
            bRet = true;
      }
      finally
      {
            SetErrorMode(uOrigErrMode);
      }
      return bRet;
}
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 11987724
Closed, 200 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

628 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