How to correct "Access denied" for a file (.txt or .csv) written & saved (in installation folder) by the software while doing calculation & then use it for further calculation in a software written in Visual Basic?

VKSB 236 Reputation points
2023-12-24T15:50:21.33+00:00

Hi,

After installing my Astrology program ("Astro Prog") written in VB, whenever I open it I get this "Error" message;

System.UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\Astro Prog\Detected Moon positions.txt' is denied.

To correct it, I have to go to the "Program Files (x86)" --> Astro Prog --> Right Click it --> Properties --> Security --> Edit --> Select "Users" --> Tick "Full Control".

Is there any way to prevent this "Error" occurring?

I want to know how to give "Full Control" to the "Installation Folder" on programming.

Could you please let me know?

Thanks

VKSB

Developer technologies VB
{count} votes

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-12-24T16:05:18.12+00:00

  2. MotoX80 36,291 Reputation points
    2023-12-24T16:25:27.99+00:00
    0 comments No comments

  3. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-12-26T08:31:34.2933333+00:00

    Hi @VKSB ,

    If you want to give "Full Control" to the "Installation Folder" on programming, try using DirectorySecurity Class with FileSystemAccessRule Class.

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.