Acces is denied

Lambert, Mark (US) - ISR 21 Reputation points
2022-03-21T16:28:33.693+00:00

After an update to Visual Studio Pro (V 16.11.11), I am no longer able to execute this simple snippet of code:

System.Diagnostics.Process.Start(@"C:\Users\U210237\Documents");

I now get this error:

185278-image.png

What do I now need to do to prevent this error. Previous versions did not generate this errors. I have admin privilege on my machine to I should not get this error.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,715 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,408 questions
{count} votes

Accepted answer
  1. Karen Payne MVP 35,201 Reputation points
    2022-03-22T11:45:13.79+00:00

    Try

    Process.Start("explorer.exe", 
        Environment.GetFolderPath(
            Environment.SpecialFolder.MyDocuments));
    

    And this will work also

    var p = new Process { StartInfo = new ProcessStartInfo("C:\\Users\\paynek\\Documents") { UseShellExecute = true } };
    p.Start();
    

    I'd go with the first simply because there is less code and we get the same outcome.


1 additional answer

Sort by: Most helpful
  1. RLWA32 41,206 Reputation points
    2022-03-21T17:50:27.977+00:00

    Explorer is a single-instance application. Attempts to start a second instance just hand-off the requested action to the already running instance. So the instance of explorer that attempts to open the file system folder that belongs to a different user is made by the process that is running as the logged-on user. Even when the logged-on user is a member of the Administrators group explorer is running with a filtered token that does not contain elevated privileges. And running the code in an elevated process doesn't change anything. The result is the same -- the explorer process that attempts the folder access is running without elevated privilege so the attempt to open a different accounts profile folders fails with access denied.

    See Explorer is a single-instance application, but you can find other ways to get the effect of running a separate instance

    1 person found this answer helpful.
    0 comments No comments