Avatar of MadRiverLizard
MadRiverLizard

asked on 

executing a .BAT file using ASP.NET C# IIS6 Win2k3

In writing middleware to connect a new asp.net app with some older functionality that this current shop uses I have been challenged to get an asp.net page to execute a .BAT file with command line arguments.

I have seen several models here on ee, and some of the solutions that worked well wouldn't allow for command line arguments. The ones that did have the option for command line arguments simply didn't work for me.

The bat file executes in a win2k3 IIS6 enviornment. The bat file opens up isql, runs a few procedures using ideo sql, then writes a few logs.

I have changed the permissions on the folder and file to run at an adequate level of permission for the isql and the bat.

Has anyone tackled this issue and won?
Thanks a TON for the help!

MRL
ASP.NET

Avatar of undefined
Last Comment
coerrace
ASKER CERTIFIED SOLUTION
Avatar of glsac
glsac
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

You can use System.Diagnostics namespace to execute anykind of dos file. Make sure that you give the appropriate access to the relevant ASP .NET account on the folder where you want to do that.

using System;
using System.Diagnostics;

public class FileManager
{
    public string LaunchFile()
    {
          string output = "";
                              Process process=new Process();
                              ProcessStartInfo startInfo=new ProcessStartInfo();
                              startInfo.FileName="FILE_PATH";
                              startInfo.UseShellExecute = false;
                              startInfo.Arguments="-ARG1 \""+ARG1+"\"";
                              process.StartInfo=startInfo;
                              process.StartInfo.RedirectStandardOutput = true;
                              process.Start();
                              output = process.StandardOutput.ReadToEnd();      
                              process.WaitForExit();
                                                                                return output;
    }
}

HTH, Nauman.
Avatar of MadRiverLizard
MadRiverLizard

ASKER

Thanks for the speedy reply.

I will have 2 arguments, how would I format that?
startInfo.Arguments="-ARG1 \""+ARG1+"\"";
startInfo.Arguments+="-ARG1 \""+ARG2+"\"";
?

Why are there '-' in front of the "-ARG1 's?

Thanks for the help, I am looking forward to trying this solution.
Avatar of MadRiverLizard
MadRiverLizard

ASKER

Ok, understood the '-'s were for switches, however this .bat file the arguments are simply 2 values seperated by a space.
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

startInfo.Arguments= Arg1 + " " +Arg2;

Best, Nauman.
Avatar of MadRiverLizard
MadRiverLizard

ASKER

Nauman, I am simply not having success with the above solution. Any other suggestions? This app is running on server2003, could that be an issue?
Avatar of coerrace
coerrace

If I have inside the .bat commands like delete, copy works perfect but if i put commands like xcopy or unrar.exe on the .bat when asp execute appears work because asp.net detect the file and appears execute but the results are nothing. WIth commands like copy like I said works perfect but xcopy no or unrar is strange. Any suggestion?
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo