locked
System.Diagnostics.Process.Start does not work from IIS server RRS feed

  • Question

  • Hi,

    I have System.Diagnostics.Process.Start coded in my web page. It works fine when I ran it from MS IDE, but when I deployed in IIS it does not work.

    I tried the following,

    Enabled checkbox in IIS Admin service ->logon Tab - Allow services to interact with desktop

    Also

    Set the application pool to local system.

    But still it is not working. Please help me to solve.

    Monday, April 23, 2012 8:07 PM

Answers

  • Then you have think it wrongly. Even if you somehow able to open the (notepad, etc.) there, the application is opened on server-side, which means the user of your website won't be able to see it.

    To do what you're trying to do, you should:

    1) Write the required header as described in here (See the answer marked there).
    2) Write the resulting text content to a MemoryStream, then pipe it to the Response using Response.BinaryWrite(), following by Flush(). Alternatively if the file is already on disk, try using Response.TransmitFile() instead.




    • Edited by cheong00Editor Tuesday, April 24, 2012 3:43 AM
    • Marked as answer by sakthimind Tuesday, April 24, 2012 5:50 AM
    Tuesday, April 24, 2012 3:38 AM
    Answerer

All replies

  • Hi,

    I want to display the *.txt file which I created in my website. In my web application (C#), I have created a file and the same needs to be displayed with content to the users.

    I have used  System.Diagnostics.Process.Start("FileName.txt"); It works fine, If I run it from VS. If I configure from IIS, it does not work. So I prefer, some other options to create a file and display the same file to users.

    Please advise me.

    Thanks & Regards,

    Sakthivel. S

    • Merged by Lie You Tuesday, April 24, 2012 5:07 AM Merged them to keep good discuss.
    Monday, April 23, 2012 4:38 PM
    1. Wrong forum.  You should ask your ASP.net questions @ http://forums.asp.net.
    2. You have a misconception:  Server-side code runs in the server, not the client.  That Process.Start() call is server-side code.  Result:  The text file is opened in the server, not the client.

    Jose R. MCP

    Monday, April 23, 2012 11:07 PM
  • No, that's not how it works.

    Setting "Allow services to interact with desktop" will just allow "IISAdmin" to interact with desktop, which it won't because it has no UI.

    Your code runs inside "w3wp" process, so is never given right to spawn process that is interactive with desktop.

    So your design has architectural defects. Please think again on what will work.

    Or if you provide more detail on what you really want to do, we may be able to give you some suggestions.

    Tuesday, April 24, 2012 1:58 AM
    Answerer
  • Thanks for your response.

    My request is : When I clicked on a button in website, I have to display a *.txt or *.CSV file. I have a dataset and it can be used to write in file.

    Approach I used: Created *.CSV file in server and tried to display to the user. So used Diagostic process start.

    Not sure how to approach above requirement.

    Thanks in advance!.

    Regards,

    Sakthivel.


    • Edited by sakthimind Tuesday, April 24, 2012 2:54 AM
    Tuesday, April 24, 2012 2:52 AM
  • Hi sakthimind,

    ASP.NET Web page and server control code executes in the context of the ASP.NET worker process on the Web server. If you use the Start method in an ASP.NET Web page or server control, the new process executes on the Web server with restricted permissions. The process does not start in the same context as the client browser, and does not have access to the user desktop. http://msdn.microsoft.com/en-us/library/0w4h05yb.aspx

    - Give permission for ASP.NET worker process account

    to interact with desktop or allow ASP.NET worker process to run in SYSTEM account.

    - Enable IIS Admin Service to interact with desktop

    To configure this, follow this steps.

    • a. Open Control Panel and follow these steps: For Windows NT: click Services. For Windows 2000, Windows XP, and .NET Server: click Administrative Tools, and then click Services.

    • b. Double-click IIS Admin Service.

    • c. On the Log On tab, select the Allow Service to Interact with Desktop check box. Remember to run IIS Admin Service as a local system.
    • d. Stop and restart the IIS Admin Service.

    Regards, http://shwetamannjain.blogspot.com

    Tuesday, April 24, 2012 3:05 AM
  • Hi sakthimind,

    ASP.NET Web page and server control code executes in the context of the ASP.NET worker process on the Web server. If you use the Start method in an ASP.NET Web page or server control, the new process executes on the Web server with restricted permissions. The process does not start in the same context as the client browser, and does not have access to the user desktop. http://msdn.microsoft.com/en-us/library/0w4h05yb.aspx

    - Give permission for ASP.NET worker process account

    to interact with desktop or allow ASP.NET worker process to run in SYSTEM account.

    - Enable IIS Admin Service to interact with desktop

    To configure this, follow this steps.

    • a. Open Control Panel and follow these steps: For Windows NT: click Services. For Windows 2000, Windows XP, and .NET Server: click Administrative Tools, and then click Services.

    • b. Double-click IIS Admin Service.

    • c. On the Log On tab, select the Allow Service to Interact with Desktop check box. Remember to run IIS Admin Service as a local system.
    • d. Stop and restart the IIS Admin Service.

    Regards, http://shwetamannjain.blogspot.com

    Tuesday, April 24, 2012 3:07 AM
  • Then you have think it wrongly. Even if you somehow able to open the (notepad, etc.) there, the application is opened on server-side, which means the user of your website won't be able to see it.

    To do what you're trying to do, you should:

    1) Write the required header as described in here (See the answer marked there).
    2) Write the resulting text content to a MemoryStream, then pipe it to the Response using Response.BinaryWrite(), following by Flush(). Alternatively if the file is already on disk, try using Response.TransmitFile() instead.




    • Edited by cheong00Editor Tuesday, April 24, 2012 3:43 AM
    • Marked as answer by sakthimind Tuesday, April 24, 2012 5:50 AM
    Tuesday, April 24, 2012 3:38 AM
    Answerer
  • Thanks. It solved my issues.
    Tuesday, April 24, 2012 5:50 AM