Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

cmd - How to run silent installer in C#

I have the following C# code:

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Process.Start("cmd.exe", "/c" + desktopPath + "" + "MyInstaller_7.1.51.14.exe –s –v –qn");

The first line gets the path of my desktop where the .exe is located. The string desktopPath is used in the second line.

The second line is supposed to start the installer in silent mode, so that the process runs in the background and the installation wizard does NOT appear at all. Running the string result of desktopPath + "" + "MyInstaller_7.1.51.14.exe –s –v –qn" in the command prompt works just fine, and the installer runs in silent mode. In case anyone is wondering, the string result of

desktopPath + "" + "MyInstaller_7.1.51.14.exe –s –v –qn"

is

C:UsersMEDesktopMyInstaller_7.1.51.14.exe -s -v -qn

and running this in the command prompt runs the installation in silent mode.

Unfortunately, triggering the same command in C# code as this:

Process.Start("cmd.exe", "/c" + desktopPath + "" + "MyInstaller_7.1.51.14.exe –s –v –qn");

does not run the installer in silent mode. Instead, the wizard comes up, visible to the user.

Does anyone know how I can modify this:

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Process.Start("cmd.exe", "/c" + desktopPath + "" + "MyInstaller_7.1.51.14.exe –s –v –qn");

so that the installer actually runs in silent mode, without the installer UI showing??

SIDE NOTE: –s –v –qn are switches for running in silent mode.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this, it works for me:

ProcessStartInfo psi = new ProcessStartInfo();
psi.Arguments = "–s –v –qn";
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.FileName = "MyInstaller_7.1.51.14.exe";
Process.Start(psi);

I don't know if the arguments you provided tried to hide the window, but perhaps like this, part of it won't be neccesary anymore.

Note that I used "notepad.exe" for my tests which were successful. Perhaps your installer reacts differently.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...