Executing CommandLine Using c#

private void Install_Click(object sender, EventArgs e)
{

try{
DeleteFromTemp();
string path = txtident.Text;
string source = "\"" + txtident.Text + "\"";
// string target = @"""%temp%\New Folder""";
string target = @"""%temp%""";
string passive = "passive TARGETDIR";
string MSI = @"""C:\Windows\System32\msiexec.exe""";
string commandLine = MSI + "/a " + source + "/qb " + "/" + passive + "=" + target + " ";
string commandLine1 = MSI + "/x" + target + "/q " + " ";
// To delete Previous Folders From Temp Location// DEL /F /S /Q %TEMP%//string commandLineDelete = "DEL " + " /F " + " /S" + " /Q " + target + " ";

////
string tempGETCMD = null;System.Diagnostics.
ProcessStartInfo StartInfo = new System.Diagnostics.ProcessStartInfo();StartInfo.FileName =
"cmd";StartInfo.RedirectStandardInput =
true;StartInfo.RedirectStandardOutput =
true;StartInfo.UseShellExecute =
false; //required to redirect CMDprocess.StartInfo = StartInfo;
CMDprocess.StartInfo.CreateNoWindow =
true;CMDprocess.Start();
System.IO.
StreamReader SR = CMDprocess.StandardOutput;System.IO.
StreamWriter SW = CMDprocess.StandardInput;SW.WriteLine(commandLine);

///////////////////
// SW.WriteLine(commandLineDelete);

////////////SW.WriteLine("exit"); //exits command prompt window tempGETCMD = SR.ReadToEnd(); //returns results of the command window SW.Close();
SR.Close();
open();
//this.Close(); }
catch (Exception ex){

throw ex;}
}





private void open(){

try{
// string source = @"""%temp%\\New Folder\\ProgramFilesFolder\\Source\\FireFly\\FireflyInstallerUI.exe""";string source = @"""%temp%\\ProgramFilesFolder\\\FireFly\\FireflyInstallerUI.exe""";
// string source = @"""%temp%\\New Folder\\FireflyInstallerUI.exe""";// DEL /F /S /Q %TEMP%string cmd = "cmd.exe /k";
string commandLine = cmd + source;
string tempGETCMD = null;
Process CMDprocess1 = new Process();System.Diagnostics.
ProcessStartInfo StartInfo = new System.Diagnostics.ProcessStartInfo();StartInfo.FileName =
"cmd";StartInfo.RedirectStandardInput =
true;StartInfo.RedirectStandardOutput =
true;StartInfo.UseShellExecute =
false; //required to redirect CMDprocess1.StartInfo = StartInfo;
CMDprocess1.StartInfo.CreateNoWindow =
true;CMDprocess1.Start();
System.IO.
StreamReader SR = CMDprocess1.StandardOutput;System.IO.
StreamWriter SW = CMDprocess1.StandardInput;SW.WriteLine(commandLine);

//ProcessClose();SW.WriteLine("exit"); //exits command prompt window }
catch (Exception ex){

throw ex;}
}

Comments