Overblog
Edit post Follow this blog Administration + Create my blog

Call .exe file from C# and send the Arguments

March 7 2009 , Written by Balavardhan Published on #ASP.Net

Call an .Exe files from the dotnet Application and Pass the arguments to .Exe application

Required dotnet Name Space
Imports System.Diagnostics

Create objects for ProcessStartInfo and Process

VB
Dim startprocess As New ProcessStartInfo
Dim myprocess As Process


C#
ProcessStartInfo startprocess = null;
Process myprocess = null;


Set the Working directory Property for Processstartinfo Object i.e. Working Directory means, the Directory which have and .exe file.

startprocess.WorkingDirectory = Request.MapPath("~/")


Set the Working Filename Property for Processstartinfo Object i.e. .exe filename.

startprocess.FileName = Request.MapPath("Media Monitors\GetMedia\GetMedia.exe") ' "C:\Program Files\Media Monitors\GetMedia\GetMedia.exe"


Set the Arguments Property to send the parameters to exe file

startprocess.Arguments = "/S /F: a.in"


Set the Output property

startprocess.RedirectStandardOutput = True

Start the Process

myprocess = Process.Start(startprocess)


sleep some time.. if the .Exe file will take the time to execute

System.Threading.Thread.Sleep(2000)


Close the Process

myprocess.Close()



Ex :

startprocess.WorkingDirectory = Request.MapPath("~/")
startprocess.FileName = Request.MapPath("Media Monitors\GetMedia\GetMedia.exe") ' "C:\Program Files\Media Monitors\GetMedia\GetMedia.exe"
startprocess.Arguments = "/S /F:" & argfilename
startprocess.UseShellExecute = False
startprocess.RedirectStandardOutput = True
myprocess = Process.Start(startprocess)
System.Threading.Thread.Sleep(2000)
myprocess.Close()
Share this post
Repost0
To be informed of the latest articles, subscribe:
Comment on this post