Deverill
Deverill

Reputation: 971

Run a server-side exe from ASP (beginner)

I have what should be a simple thing but my unfamiliarity with .NET and web programs is hindering me. I'm a straight up old-school C programmer who has been programming ASP and ASP.NET lately for an ecommerce site.

I have an ASP program that synchronizes 2 databases. I also have a VB.NET program compiled down to an EXE that fills the source database before the synch happens. In the back of my mind I know I should be able to link the VB & ASP .NET programs together since that's the power of .NET. Alternatively, if I could run the EXE from ASP it would be just as well for my project. I do have the source to both programs. The ASP script was written with a text editor - the VB was in VB 2008 Express.

Please assume I know nothing of linking assemblies and such because I don't - I just read that in an article. I'd prefer ASP but if necessary I could use the ASP.NET script to launch the EXE. The code is legacy ASP with VBScript so all our ASP.NET stuff is the VB flavor as well. C# makes my other programmer's head hurt so for his sake this will have to remain VB.

Is there a way I can relatively easily launch the EXE pre-sync program and have it run when the ASP synch script starts?

The server is MS Windows Server 2003 SP2 / IIS 6.0 / the .NET version is 2.0.50727.3603. Thanks!

By the way - I'd love to "learn to use .NET properly" but time is short for this project and in-depth research will have to wait.

EDIT: Aaron's answer below gets me most of the way to the solution but I'm getting:

Exception Details: System.ComponentModel.Win32 Exception: Access is denied
Source Error: Line 17: process1.Start();
Ideas anyone?

SOLUTION: Aaron's answer below plus the knowledge that ~/ in MapPath is the virtual root of the website and the file to run is relative to that.

Upvotes: 3

Views: 13077

Answers (2)

Russ Bradberry
Russ Bradberry

Reputation: 10865

If you have the source for both then you could open the project for the EXE and copy the functionality to a new class library, then reference this class library in the web app and call the method that does the database filling from the web app.

Upvotes: 2

Aaron M
Aaron M

Reputation: 2563

// Create An instance of the Process class responsible for starting the newly process.

System.Diagnostics.Process process1 = new System.Diagnostics.Process();

// Set the directory where the file resides

process1.StartInfo.WorkingDirectory = Request.MapPath("~/");

// Set the filename name of the file you want to open

process1.StartInfo.FileName = Request.MapPath("foo.exe"); 

// Start the process

process1.Start(); 

Upvotes: 8

Related Questions