0

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";              
}
Azizul H
  • 101
  • 2
  • 10
  • Why are you opening Notepad on a web server? – Neil Aug 05 '21 at 11:17
  • This is an example for the purpose of simplifying my post and hiding my server/application name, which is a self-developed windows console app. – Azizul H Aug 05 '21 at 15:35
  • OK, why are you trying to open ANY program from a web server? Are you expecting a user to visit your web site, and then open a program on their local PC, or open a program on the web server? You can set the IIS user to be something other than DefaultAppPool, but it will still run on the web server. I just don't understand what you are trying to achieve. – Neil Aug 05 '21 at 16:09
  • I'm making a web site that takes data from other server using Dynamic Data Exchange (DDE). It requires a DDE client (the self-developed console app) to be opened in the web server. Users will only open the website from the web server itself in an office intranet using the URL http://localhost/website/Main.aspx. So the web site users, the program to be opened and the web servers are all in the same machine. Starting the program isn't a problem but the DDE client cannot pull any data if opened by DefaultAppPool. – Azizul H Aug 06 '21 at 03:42
  • It's good to know I can set the IIS user to be something other than DefaultAppPool. I will do that if I am unable to make my code works. – Azizul H Aug 06 '21 at 03:45

0 Answers0