Using vs2022 community I get varied "access denied" error depending on how exe is started

HowardMontemurro-7208 50 Reputation points
2023-03-06T17:16:38.9366667+00:00

With an HP desktop using Win10 I have a small VS project ("Cage") to be used as substitute for windows dialog in a suite of 12 other projects which will start the process "Cage" with different parameters. One of the parameters is the name of the file that the calling project wants too receive the (dialog) answer.

When I run "Cage" from VS2022 Community in design mode (using Properties\Debug\command line arguments) the project ("Cage") writes SUCCESSFULLY to the answer file (command line parameter),

However, when I call (PROCESS.START) the "Cage" exe file from any the mainline projects, OR A TEST CALLING PROJECT, the "Cage" write (using stream writer) fails and I am confronted by the Unhandled Exception - Access to the path .... is Denied - even though "Cage" notes via a message box that the attributes of NEITHER the file or its folder (path get directory /name) have a "read only" attribute.

ALSO, I tested with Windows Defender turned OFF getting same resulta.

I have searched the internet for (MS/VS/VB etc.) answers for at least 20 hours in the past 3 days but have not found the solution that I know must be there as my experience has been that there is always someone, somewhere who has suffered this and most of my previous problems

HELP! Please and thank you. ANY HELP OUT THERE?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,142 questions
{count} votes

Accepted answer
  1. Tianyu Sun-MSFT 30,821 Reputation points Microsoft Vendor
    2023-03-08T02:32:47.51+00:00

    Hello @HowardMontemurro-7208 ,

    Welcome to Microsoft Q&A forum.

    Does this issue only appear on specific file/folder? Is it possible for you to try to write to another file/folder and check if the same error appear?

    If you reboot your machine and then directly call (PROCESS.START) the “Cage” exe file from any the mainline projects, will the same error appear?

    If you right-click the blocked file/folder => click Properties => Switch to Security tab => click the Edit button => select the corresponding user => assign Full control permission to this user => click Apply and test again, will the file/folder be successfully accessed?

    Please also try the solutions that mentioned in this document: "Access Denied" or other errors when you access or work with files and folders in Windows.

    Besides, can you confirm that you have administrator permission on your machine? If the error persists, could you please share us a minimal reproducible sample to check further?

    Please feel free to let us know the result.

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


1 additional answer

Sort by: Most helpful
  1. HowardMontemurro-7208 50 Reputation points
    2023-03-10T17:18:31.78+00:00

    Tianyu:

    Thank you for your Answer because your suggestions found the solution.

    While preparing simple versions of the caller and the Cage exe, as you requested,  I discovered a minute but telling error in the Process.StartInfo which corrupted the Path of the file to be used to return the {dialog] answer.

    I am deeply embarrassed by my ineptitude in failing to catch the error and especially for wasting your valuable time and for this I apologize. I hope that “To Err is Human, to Forgive Divine” is within you.

    Howard

    PPS In my original investigations I was misled by the "Access Denied" part of the exception message. The true error was that the path of the stream writer ended up as a directory rather than a File. I assume that since this error occurs so rarely that a more specific message is not needed for the general [smarter than I] population.

    PPS Please delete this Question (to contain my embarrassment)

    1 person found this answer helpful.

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.