"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Tuesday, October 12, 2010

Run application in asp.net c#

you have a button on ASP.NET page, when press this button - one application is invoked.


the code to run application (for example, notepad) is (on C#)

System.Diagnostics.Process.Start("notepad");


On details:

            ProcessStartInfo processStartInfo = new ProcessStartInfo();

            processStartInfo.FileName = @"c:\WINDOWS\system32\notepad.exe";

            processStartInfo.Arguments = @"c:\test.txt";

            Process.Start(processStartInfo);


but the problem is that the application doesn't run, i.e. no window is opened.

Note that ASP.NET code is executed on the SERVER.

Solution:

ASPNET user under which application is run should have appropriate security settings.

1. change local policies for APSNET user:
in WinXP: run secpol.msc

go to Local Policies->User Rights Assignment

find "Deny logon locally" and remove ASPNET user from it.
also find "Deny logon .. terminal" and remove ASPNET user from it.



2. Security for files.
if your application needs also to work with files (open, save, etc) you have to change security settings for the folders to allow user ASPNET modify nedeed files.

to do this:
- In Explorer right button mouse click the folder and select "Properties"
- In Security tab, add "ASPNET" in and give desired permissions (Read, Write, Execute, etc).


To test how it works without starting ASP.NET site you can try run in Windows command line:

runas /user:ASPNET "notepad.exe"

it asks you for the password of ASPNET user. enter the password. 
if everything is done correct you will see opened application (notepad in our example) in new window.


I've tried this on my Windows XP Professsional and it worked fine.


Read more

- Unable to Start a Process from ASP.NET
http://support.microsoft.com/kb/555134


- ASP.NET Impersonation
http://msdn.microsoft.com/en-us/library/aa719560.aspx

- How to configure the process identity for the ASPNET account in ASP.NET 1.1 when you use IIS 5 Isolation mode in IIS 6.0 on Windows Server 2003

Have a nice day... 'N happy Coding :)

No comments: