Tomas
Tomas

Reputation: 18107

How to execute EXE file on Windows 2008 using ASP.NET

How to execute EXE file on Windows 2008 using ASP.NET and IIS7? I have tried to run code below but it seems do not work. The code is executed without any error but I do not see Notepad in Processes list. Everything works fine if I use ASP.NET developer server but not with IIS7.

string enginePath = "notepad";

var password = new System.Security.SecureString();
foreach (char character in ConfigurationManager.AppSettings["Credentials"])
    password.AppendChar(character);

var p = new Process
            {
                StartInfo =
                    {
                        FileName = enginePath,    
                        UseShellExecute = false,
                    }
            };


p.StartInfo.UserName = "Administrator";
p.StartInfo.Password = password;

p.Start();

Upvotes: 0

Views: 1732

Answers (2)

Tomas
Tomas

Reputation: 18107

I have removed lines below and it suddenly started working. I can't explain how it is possible to run exe under IIS7 account but it is working.

p.StartInfo.UserName = "Administrator";
p.StartInfo.Password = password;

Upvotes: 0

Cos Callis
Cos Callis

Reputation: 5084

In response to security concerns Microsoft has continually increased the isolation of the IIS process such that you can not (or I have not found a work around which will allow you to...) invoke anything outside the IIS application domain directly. You can build a Windows service which can use WCF channels to cross that boundary indirectly. That service (configured to be allowed to interact with the desktop) can in turn launch your Notepad.exe.

It is a bit of a kludge to make it happen and I will certainly be interested to see if someone else has a better answer.

Upvotes: 1

Related Questions