0

I know that this is question was already asked but i couldn't find any answer . I have this code i'm trying to run an app with a specific user but gives error that file could not be found even if the file is there.

    static void Main(string[] args)
    {
        System.Diagnostics.ProcessStartInfo myProcess = new System.Diagnostics.ProcessStartInfo("cinegy.exe");
        myProcess.WorkingDirectory =Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)+ "\\Cinegy\\Cinegy Workflow 8.5.8\\";
        System.Security.SecureString password = new System.Security.SecureString();

        string uspw = "mypass";

        foreach (char c in uspw)
        {
            password.AppendChar(c);
        }
        myProcess.UserName = "myuser";
        myProcess.Password = password;
        myProcess.Domain = "mydomain";
        myProcess.UseShellExecute = false;
        try
        {
            System.Diagnostics.Process.Start(myProcess);
        }
        catch (Exception ex) 
        {
            Console.WriteLine(ex.Message);
            Console.ReadLine();
        }
    }
}

Thanks

Error is |The system cannot find the file specified|

adi sba
  • 621
  • 1
  • 12
  • 32

1 Answers1

2

If you use

UseShellExecute = false

it ignores WorkingDirectory

You can either set UseShellExecute to true and have a cmd shell. Or you add the location of the process to path of the process you are running:

string path = System.Environment.GetEnvironmentVariable("path");
path += ";" + Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Cinegy\\Cinegy Workflow 8.5.8\\";
System.Environment.SetEnvironmentVariable("path", path);
Raj Ranjhan
  • 3,869
  • 2
  • 19
  • 29