Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 170437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:48:29+00:00 2026-05-11T12:48:29+00:00

I need to know if my program can write files to the disk (HDD,

  • 0

I need to know if my program can write files to the disk (HDD, floppy, flash, CD) from where it is running. I have tried something like:

     {$I-}      Rewrite(myFile);                                             {$I+}   Result:= (IOResult = 0); 

The problem is that if the disk is read-only, Windows gives me an error message telling me that

‘appName.exe – Write Protect Error The disk cannot be written to because it is write protected. Please remove the write protection from the volume USB_BOOT in drive D:. Cancel TryAgain Continue’

How can I test for write access without raising any error/warning messages? Thanks.


Edit:

Ok. The ‘bug’ has nothing to do with the above mentioned piece of code. I only thought that it appears there. I move the code to the read-only disk and ran it from there. The bug appears in a function called ‘CreateShortcutEx’, on this line:

 MyPFile.Save(PWChar(WFileName),False); 

MyPFile is declared like this:

var  MyObject  : IUnknown;  MySLink   : IShellLink;  MyPFile   : IPersistFile;  Directory : String;  WFileName : WideString;  MyReg     : TRegIniFile; begin  MyObject := CreateComObject(CLSID_ShellLink);  MySLink  := MyObject as IShellLink;  MyPFile  := MyObject as IPersistFile;  ..... end; 

So, why is MyPFile trying to write to the application’s drive (the one that is read-only) if the WFileName parameter is ‘C:\documents and settings\bla bla’ ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:48:29+00:00Added an answer on May 11, 2026 at 12:48 pm

    Call the Windows API SetErrorMode() function to disable the error message box.

    Edit:

    I just tried, and this:

    procedure TForm1.Button1Click(Sender: TObject); var   Str: TStream;   OldMode: Cardinal; begin   OldMode := SetErrorMode(SEM_FAILCRITICALERRORS);    try     try       Str := TFileStream.Create('z:\foo.txt', fmOpenReadWrite);       try        finally         Str.Free;       end;     except end;   finally     SetErrorMode(OldMode);   end; end; 

    works as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a C program that will allow me to read/write files
I have been given a project where i need to write a program which
I need to know when the memory will be allocated for a particular program.
I need to know how to turn on Code Coverage when running TFS builds
I need to know, from within Powershell, if the current drive is a mapped
I need to know what internet connection is available when my application is running.
I am looking for a method to monitor a running program that I have
I am new at haskell, I have to write a program context-aware,so I thought
I have a Python script and a C program and I need to pass
I want to write a Python program that makes PNG files. My big problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.