0

I am trying to run the process with different user. When I run normal "notepad.exe" it works fine. But when I change the file to any other executable with full path(C:\\Program Files\\Microsoft Office\\Office15\\Excel.exe) or (C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\AcroRd32.exe) it doesn't work. Instead gives errors like attached in pic.

Any suggestions...??

enter image description hereenter image description here

static void Main(string[] args)
        {
            SecureString securePwd = new SecureString();

            string password = "P@ssw0rd";
            SecureString sec_pass = new SecureString();
            Array.ForEach(password.ToArray(), sec_pass.AppendChar);
            sec_pass.MakeReadOnly();

            Process p = new Process();

            ProcessStartInfo ps = new ProcessStartInfo();

            p.StartInfo.FileName = "notepad.exe";
            p.StartInfo.Arguments = "C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\welcome.pdf";
            p.StartInfo.WorkingDirectory = "C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\";
            p.StartInfo.ErrorDialog = true;
            p.StartInfo.EnvironmentVariables.Add("TempPath", "C:\\Temp");
            p.StartInfo.Domain = "testdom";
            p.StartInfo.UserName = "testuser";
            p.StartInfo.Password = sec_pass;
            p.StartInfo.RedirectStandardError = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.UseShellExecute = false;
            p.Start();

            StreamReader myStreamReader = p.StandardOutput;
            // Read the standard error of net.exe and write it on to console.
            Console.WriteLine(myStreamReader.ReadLine());
            p.Close();

        }
Mashhoor Gulati
  • 127
  • 3
  • 13

2 Answers2

1

Notepad doesn't store any user-specific settings. I'm certain all of the Office products do, and it wouldn't surprise me if Acrobat does too.

So, first thing to fix is to make sure that your ProcessStartInfo sets LoadUserProfile to true. That may be sufficient.

However, sometimes applications also act quite differently when run for the first time versus any subsequent launches, so I'd also make sure that you have, at least once, launched each of these applications as the intended target user, whilst you're actually logged onto the machine as that user (versus just launching a single process as that user).

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
0

In your code example your trying to open a pdf document in notepad.

Just checking, what happens when you change the file name to the adobe exe (you may need to add the path to the exe) instead of notepad.exe

Tony
  • 101
  • 1
  • 2
  • 7