user584018
user584018

Reputation: 11304

I have "User1" home folder, but my app looking "Default" folder, why?

My winform executable calling AppData of the user directory.

Now When I am trying run my app with User1 using below code, my app looking "Default" user directory instead of User1 directory. What could be the reason?

Access to path 'C:\Users\Default\AppData\Local\DataFolder is denied

  string CommandDirectory = @"C:\Program Files (x86)\Apps\";

        var process = new Process
        {
            StartInfo =
                {
                    FileName = string.Format("{1}{0}Utility.exe", Path.DirectorySeparatorChar, CommandDirectory),
                    WorkingDirectory = string.Format("{0}", CommandDirectory),
                    RedirectStandardError = true,
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    UserName = "User1",
                    Password = "Password1".ToSecureString(),
                    Domain = "Machine-Name",
                },
        };

        process.Start();

Note - If I use verb and remove UserName, Password, Domain, then works find and looks correctly for Admin user folder,

UseShellExecute = false,
                    //UserName = "User1",
                    //Password = "Password1".ToSecureString(),
                    //Domain = "Machine-Name",
                    Verb = "runas"

Upvotes: 1

Views: 63

Answers (1)

mjwills
mjwills

Reputation: 23864

I suspect you forget to set LoadUserProfile to true.

As per the docs:

The default is false.

When you need it to be true.

Upvotes: 2

Related Questions