Ask the Expert

Calling a Windows application

I developed a Web application. One of its functions is to call a Windows application. I use notepad.exe for testing purpose. However, the .exe does not show up on the screen. It is only running in the background when I check the Task Manager. My code looks like this:

Process DYProcess = new Process();
DYProcess.StartInfo.FileName = @"c:\winnt\notepad.exe";
DYProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
DYProcess.Start();
ASP.NET is a server application, and everything you code in C#, or any other .NET language, is executed on the server-side. Therefore, opening a Notepad application is just weird, to say the least. Do you expect some administrator to be sitting in front of the server waiting for a Windows application to open up in response to a user's request for a page? Being a server application, the ASP.NET worker process account doesn't even have the permission to open UI elements, because they can cause the process to be kept waiting for user response that may never come. After all, servers shouldn't even be used by end-users regularly; therefore, it's most probable that there is no user session initiated at all.

I bet what you're trying to do is start a Windows application on the client side. If that is the case, ASP.NET has nothing to do about it -- neither does .NET. You have to use plain JavaScript at the HTML level to start the process at some page event. I'm sure there are other ways of doing this, but one of them is using the Shell object from WSH (which must be installed on the client machine, of course, but comes built-in with WinXP/2k AFAIK):

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run("cmd.exe")

You will receive the usual warning about security and ActiveX execution.

This was first published in October 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: