简体   繁体   中英

Specifying command line parameters in Process.start

I am trying to write a windows application in C# where - the user selects an MSI file and an Instance Name and on clicking the 'Run Installer' button.......the MSI file will be invoked with the instance name as a parameter.

So basically the the command generated will look like:

msiexec  /i "E:\Local Profile\Desktop\BranchBankingConnectorSetup.msi" MSINEINSTANCE=1 TRANSFORMS=:Instance1

The problem is.....after I run the installer for the first time and Instance 1 of the Branch Banking Connectors is installed.....if I try to run again with Instance 2 - the program still brings up the Installer for Instance 1.

This is my code:

System.Diagnostics.Process p  = new System.Diagnostics.Process();
p.StartInfo.FileName = "e:\\command.bat";
p.StartInfo.UseShellExecute = false;
p.Start();

The file e:\\command.bat contains the above mention command and this file is first updated with the selected instance number and then called.

Don't use a batch file
you can pass arguments within the StartInfo

System.Diagnostics.Process p  = new System.Diagnostics.Process();
p.StartInfo.FileName = "msiexec.exe"; //You better provide a full path here
p.StatInfo.Arguments = " /i \"E:\\Local Profile\\Desktop\\BranchBankingConnectorSetup.msi\" MSINEINSTANCE=1 TRANSFORMS=:Instance1";
p.StartInfo.UseShellExecute = false;
p.Start();

尝试这个

p.StatInfo.Arguments = "required arguments"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM