How to run .EXE on button click in C#
Simple Call:
using System.Diagnostics;
This namespace provides access to local and remote processes and enables you to start and stop local system processes.
protected void Button1_Click(object sender, EventArgs e)
{
// string str = @"C:\windows\system32\notepad.exe";
{
// string str = @"C:\windows\system32\notepad.exe";
// string str = @"C:\windows\system32\winamp.exe";
string str = @"C:\Documents and Settings\RAJ\Desktop\MCNewsLetter\SendNewsletter.exe";
Process process = new Process();
process.StartInfo.FileName = str;
process.Start();
With Attributes:
using System.Diagnostics;
class Program {
static void Main()
{
LaunchCommandLineApp();
}
/// <summary>
/// Launch the legacy application with some options set.
/// </summary>
static void LaunchCommandLineApp()
{
// For the example
const string ex1 = "C:\\";
const string ex2 = "C:\\Dir";
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "dcm2jpg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;
class Program {
static void Main()
{
LaunchCommandLineApp();
}
/// <summary>
/// Launch the legacy application with some options set.
/// </summary>
static void LaunchCommandLineApp()
{
// For the example
const string ex1 = "C:\\";
const string ex2 = "C:\\Dir";
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "dcm2jpg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;
startInfo.WorkingDirectory=@"C:\WD"
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
string status=exeProcess.HasExited; //returns process execution status
}
}
catch
{
// Log error.
}
} }
}
}
catch
{
// Log error.
}
} }
Comments
Post a Comment