вторник, 2 сентября 2008 г.

ASP Net - Run Application (EXE) from ASP.Net C#

Task: run application from ASP.NET

for example,
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#)


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.


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

- ASP.NET Impersonation

- 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

4 комментария:

Rem комментирует...

Your blog is very nice...
visit my blog asp.net example

mxdev комментирует...

thank you.
your blog http://asp-net-example.blogspot.com/ is organized very well.

alI@ziba.net комментирует...

Please help me.

I added a macro to MS WinWord to print any DOC file to default printer that is a PDF writer. (mPrintDefault is macro name)

Now I write a simple code in ASPX page, to convert a sample DOC file to PDF format. (Using System.Diagnostics)

The problem is that every time I run the page, winword.exe is called by Network Service account and is remained in task bar and nothing else!

I can run below line in RUN command prompt with success:

"c:\Program Files\Microsoft Office\OFFICE12\WINWORD.EXE" "C:\test\sample.doc" /mPrintDefault /q /n"

But in ASPX page no success.

Before this, I used some other components to do this conversion. (DOC2PDF).

With local users like Administrator it was OK but within ASPX pages was unsuccessful. Every time, winword.exe was called by IUSER or NetworkService and remained in taskbar without success or result.

How I can fix this problem?
I changed all permissions for target directory to WRITE, but no success.

Best Regards

OS is Windows 2003
Code is:
Partial Class test_diag
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim psi As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo()

psi.FileName = "c:\Program Files\Microsoft Office\OFFICE12\WINWORD.EXE"
psi.Arguments = "C:\test\1.doc""/mPrintDefault /q /n"


End Sub
End Class

mxdev комментирует...

Do you need it to work under Windows Server or Windows XP ?

Let me know under which user account you see winword.exe in process list.

if you see winword.exe run under NetworkService account in process list - then i suspect you need some more steps.