Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Framework  »  Executing External Applications
Executing External Applications
by Steven Sartain | Published  10/16/2001 | .NET Framework | Rating:
Steven Sartain

Steven Sartain is a consultant currently designing and leading a VB.NET project using n-tier architecture and WebServices for Accuride International Ltd.

During his 8 year career as a developer and development lead, Steve has designed and implemented a diverse number of mission critical software solutions using VB, VBA, MS Access, C/C++, ASP, Delphi, DCOM & MTS, SQL Server, Oracle, SQL Anywhere and others. See his Resume for details.

He is also a Director of Iridium Software - a UK based bespoke software development house.

Steve is always open to take over a challenging programming opportunity. If you experience a need for a professional consultant who has all the necessary skills to take a proposition from first client meeting through to profitably and elegantly completed projects; I'm sure Steve could assist. See his Resume and Professional Statement for details.

 

View all articles by Steven Sartain...
Executing External Applications

How to execute external applications

Start a new project then add a module. Add the following code to the module:

'Author: Steven Sartain
'Last Revision: 28th August 2001
'Revision Notes: None
'Supported environments:
'                    Yes        No        Untested
'    VB4                        X
'    VB5                        X
'    VB6                        X
'    VB.NET(beta2)    X
Imports System.Diagnostics
Namespace vbCity
  Public Module modFunctions
    Public Sub ExecuteApplication(pstrApplicationName As String)
      Dim udtProcess As Process = New Process
      udtProcess.Start(pstrApplicationName)
    End Sub
  End Module
End Namespace
Generated using PrettyCode.Encoder
How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent
Tell us why you rated this way (optional):

Article Rating
The average rating is: No-one else has rated this article yet.

Article rating:3.64516129032257 out of 5
 31 people have rated this page
Article Score43374
Comments    Submit Comment

Comment #1  (Posted by Radas on 11/21/2001)

Thanks for posting an info about executing external applications in .NET framework. I am indeed able to run the process (visible in Task Manager) but what about GUI of such. Launching for example notepad.exe I would expect to see its GUI. Question : does this solution support it or it's a matter of something else, like allowing one of the windows services to be able to "interact with desktop" ?. I used to use an old ASPEXEC component but in the light that it's the unmanaged COM component good for ASP solutions I'm looking for something accurate for ASP.NET (I simply need to run external application with GUI from ASP.NET page). Thank You.
 
Comment #2  (Posted by Steven Sartain on 11/23/2001)

I'm glad the offering got you off on the right foot.
The code in this example works fine for desktop applications, but I understand your issue. I'm presuming that you're developing an intranet application?

Serge may be better advised to answer your problem (and as he's all seeing I am sure he respond fairly promptly). Perhaps instead of invoking "notepad.exe" you may want to invoke a filename. This will allow the OS to launch the most suitable application (using your registered file types).

I am however ot convinced that this will solve your problem. The issue is simply that although you have instantiated the process, you would be expected to extend you requirements about what to do with it.

What I feel you'll need to look at is the System.Security.Permissions namespace, it has a UIPermissionAttribute. Whilst I haven't tested this, I think it points you in the right direction. Let me know how you go.
 
Comment #3  (Posted by Serge Baranovsky on 11/23/2001)

Hey, it's Serge here... the "all seeing" :)

Radas is right, in standard ASP.OLD there is no way to execute an external app on the client side. If you invoke a filename without the executable name it will simply display it in the browser (if text-like file) or will offer the open/save dialog... ASPExec for ASP.OLD is the only option.

Even though I may be wrong (I'm not through the .NET class library yet - over 6000 classes !?!?!) I don't believe .NET offers anything similar to ASPExec.

Your options? Well, as you know, you still can use COM components with .NET... If you want a "pure" .NET solution you have to wait on ASPExec.NET from ServerObjects.com but since this component is free (therefore unsupported) I'm afraid it may take a while for them to release the .NET equivalent. Not very encouraging, huh?
 
Comment #4  (Posted by Raseena Sunil on 12/03/2002)

Hi,
I've a similer problem. I've to execute Vb Script file(.vbs) at the Web server(ASP.NET) using WScript.Exe. I tried using Shell function and System.diagnostics.Process class. In both cases It shows an entry in the Task Manager processes tab(CPU Time - 00:00:00) at the Web Server, nothing more. The script is not actually executed.
Both of the above functions work in Windows application but not in Web Application. I even tried to use a windows dll(Using both functions) in the web application. Is there any additional setting to be done to make this happen?
Somewhere I read that this will execute if ASPNET account is an administrator account and if the Script file does not contain any user interface(B'cause, if any is there the request is suppressed by the IIS). I tried that also, but in vein. Could you please give me a solution

Thanx in advance

Raseena Sunil
 
Comment #5  (Posted by Serge Baranovsky on 12/04/2002)

Hi Raseena,

This functionality is disabled in ASP.NET for safety reasons. You cannot execute external app from ASP.NET.

For a workaround see my prior comment. Click 'view all comments' link or use this link

http://www.devcity.net/net/view_comment_thread.aspx?fid=1&pid=9&cid=3&y=2001&m=10&d=16
 
Comment #6  (Posted by ANDRE on 02/27/2004)

you have the SHELL command to run external application!!!

SHELL("C:\WINDOWS\SYSTEM32\CALC.EXE")
 
Comment #7  (Posted by neil on 03/22/2004)

I need to call an external windows zip program command to compress a file thru my .NET application. Should I create a batch file on the fly and execute it from my programme.Is there a better way to do this?

 
Comment #8  (Posted by Prasad Papudesi on 04/14/2005)
Rating
When you try to open a process from windows service, you can see the process started from task manager but you dont really see the process on the desktop. You need to allow services explicitly to interact with the desktop if you want to display a notepad when you execute Process.Start("notepad.exe") from windows service. Inorder to do this, right click on the service that you are running and click on properties. Under LogOn tab, check "Allow Service to interact with Desktop". This should do the trick. If you have any questions, email me to prasad32377@yahoo.com

 
Comment #9  (Posted by Prashant Singh Pawar on 04/16/2005)
Rating
Can anyone tell me how to capture the output of a console based app?
Let me tell you what I am trying to do, I want to execute the C# compiler(csc.exe) from my program and then I want to store the compiling errors in a file, or to display it on the screen.
 
Comment #10  (Posted by Prasad Papudesi on 04/23/2005)
Rating
Thats exactly what I mentioned in my previous posting. You will have to explicitly allow the windows service to interact with the desktop. pls read my previous posting.
 
Comment #11  (Posted by an unknown user on 05/01/2005)
Rating
Not worth following 4 links to find
 
Comment #12  (Posted by Nancy on 05/09/2005)
Rating
I am creating a simple VB >NET application as a graphical interface to launch 1 of 3 install packages. (don't want to use Installshield's DemoShield). It seems like this will work. However, I want to wait for the called process to end before moving on with my next action. what do I need to do to modify this to "wait", ie, to run synchronously? thanks
 
Comment #13  (Posted by Vico on 06/10/2005)
Rating
I keep getting JIT Debugging: access denied. I think ASPNET account does not have enough permission to execute external executables from my ASP.NET page. I have tried to put ASPNET under the Administrators group and grant access to all folders the executables will need to access. However, it didn't work. Could you please help? I appreciate it thanks.
 
Comment #14  (Posted by an unknown user on 07/12/2005)
Rating
How do i capture the standard out and standard error
 
Comment #15  (Posted by an unknown user on 08/21/2005)
Rating
It is very useful for executing applications, and does not cause security issues like using the Windows Script Host ocx.
 
Comment #16  (Posted by an unknown user on 09/21/2005)
Rating
its is ok,,, but how can u open a file whenever u execute the system process..
like for ex notepad.exe with one file
 
Comment #17  (Posted by Meenakshi on 12/01/2005)

hey i want to execute the xsd.exe utility from windows form??? how can i do this??

 
Comment #18  (Posted by an unknown user on 12/12/2005)
Rating
It solved my prob within a giff
 
Comment #19  (Posted by an unknown user on 01/01/2006)
Rating
?-mine, where I have got?
 
Comment #20  (Posted by an unknown user on 02/09/2006)
Rating
Hi, How do I use the same function in asp.net.If psbl pls mail me on the solution harish217@hotmail.com
 
Comment #21  (Posted by Harish on 02/09/2006)
Rating
Hi,
I tried this code on asp.net and can see the process running in taskmanager for an exe.What I want is to run setup(i.e) installing software from webpage on client system where the setup file is stored on a web server within an intranet pls let me know if it's possible.
 
Comment #22  (Posted by Harish on 02/09/2006)
Rating
Hi,
I tried this code on asp.net and can see the process running in taskmanager for an exe.What I want is to run setup(i.e) installing software from webpage on client system where the setup file is stored on a web server within an intranet pls let me know if it's possible.
 
Comment #23  (Posted by an unknown user on 04/10/2006)
Rating
i used the same code for running an external exe and its working fine as expected but what is happening is once the exe has completed its job it fires session_end and application_end events; can u pls tell me how can i avoid this?? thnks
 
Comment #24  (Posted by an unknown user on 04/24/2006)
Rating
Hi, I need your help. I would wish to open an external application in asp.net but when it execute the code, there are no response in opening the application and just pass through the code. Do you know what would this happned and how to solve this?
 
Comment #25  (Posted by an unknown user on 05/31/2006)
Rating
i am facing one problem..Here is my code
Dim ShellProcess As New Process
ShellProcess.StartInfo.UseShellExecute = True
ShellProcess.StartInfo.FileName = sBatchFile
ShellProcess.Start()
ShellProcess.WaitForExit()

It opens command prompt and batch file is not running...

when i manually double click on batch file..it runs successfully..but not from vb.net application? can any one help me?
my id is ramuis78@hotmail.com

thanks in advance..

 
Comment #26  (Posted by Leo on 06/13/2006)
Rating
wanto capture keyCodes in my vb.net application from external application
 
Comment #27  (Posted by an unknown user on 09/01/2006)
Rating
The author was right on. Could not have answered the call of duty any better. Short sweet and to the point.
 
Comment #28  (Posted by an unknown user on 02/27/2007)
Rating
good solution to my problem
 
Comment #29  (Posted by an unknown user on 03/15/2007)
Rating
Hi,
This satish,
Thanks for ur posting. Its very much useful when we r trying to execute the
external applications.
thanks once again.
bye..


 
Comment #30  (Posted by an unknown user on 06/17/2007)
Rating
It is really very useful code for me, but i need one more help i am new in asp.net. with executing an exe i am alse in need of some value from this exe to my asp.net application. is it possible .if yes then please inform me.thanks in advance
 
Sponsored Links