I need to open another application (e.g. notepad) as a particular user using C# web app. I noticed when I debug in Visual Studio, notepad will be opened by my own user name but in the published web app, the user name for the opened notepad is DefaultAppPool.
Following this thread, I wrote the following C# code. Notepad will start successfully when debugging in Visual Studio but it will not start in the published web application.
There will be an error if I purposely put wrong domain/username/password but when the credentials are all correct, no error is catched but notepad does not open.
Any guide or clue on what I should do?
try
{
string path = @"C:\WINDOWS\system32\";
string app = @"notepad.exe";
Process[] pname = Process.GetProcessesByName(app);
SecureString password = new SecureString();
password.AppendChar('a');
password.AppendChar('b');
password.AppendChar('c');
password.AppendChar('d');
Process p = new Process();
p.StartInfo.WorkingDirectory = path;
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = path + app;
p.StartInfo.Domain = "mydomain";
p.StartInfo.UserName = "myusername";
p.StartInfo.Password = password;
p.Start();
LabelStatus.Text = "Success";
}
catch
{
LabelStatus.Text = "Fail";
}