Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

powershell - How to run an installation in /silent mode with adjusted settings

My goal: I want to create a CMD command that will installs a program with adjusted install settings.

If I execute my .exe install file without any parameters, I have to click myself through the installation but I am able to change the install settings, like in which folder the setup will install the program or change the status of a checkbox.

However, I want to run the installation in /silent mode, in which I don't know how to change the install settings.

So the question is:

Is there anyway to give the shell a correct installation settings and then execute the file in silent mode?

I need this because I have to run the installation on multiple computers so it would be very comfortable if I had a script that runs the installation with correct settings.

Someone please guide.

Question&Answers:os

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

1 Reply

0 votes
by (71.8m points)

Community: I'll elaborate later, but first let us do the easiest way. You could try to search for your software on sites dedicated to setup information and how to deploy various third party software silently: https://www.itninja.com/software

Similar, terser answer: Silent run installer (.exe) with parameters on Windows


1) Standard Packaging Formats: If the setup.exe wraps a standard packaging format such as an MSI file, then you generally need to find a way to extract the package inside and customize its silent installation using standardized customization mechanisms involving command lines and MSI transforms.

2) Proprietary Packaging Formats: If the setup.exe is a proprietary format you need to either repackage it in a standard format (MSI) using tools to do so, or you need to run the installer in silent mode. The latter can be unreliable, but is often done for small scale distribution.

Look and Feel: Experience can teach you what tool was used to make the setup.exe by looking at the dialogs at runtime. Sometimes you see a company name or a tool name embedded in them.


So in summary:

  1. Extract standard package if possible.
  2. Customize standard package.
  3. Repackage.
  4. Install silently using original setup.exe.

Let's briefly describe these different tasks:


Extraction of Files:

There is a forest of tools that can create setup.exe files, it is impossible to cover all of them. They might feature all kinds of different command line switches. A setup.exe can even be totally proprietary, meaning no deployment tool was used to make it at all. It might have been compiled using Visual Studio for example.

A description of tools that can be used (non-MSI, MSI, admin-tools, multi-platform, etc...).

Common tools such as Inno Setup seem to make extraction hard (unofficial unpacker, not tried by me, run by virustotal). Whereas NSIS seems to use regular archives that standard archive software such as 7-Zip can open.

I try the following command lines to see if I can do a file extract:

  • setup.exe /a (Installshield MSI)
  • setup.exe /stage_only (Installshield Suite)
  • setup.exe /x (Wise, Advanced Installer)
  • setup.exe /extract_all (Installshield Installscript)
  • dark.exe -x outputfolder Setup.exe (WiX Burn Bundles - requires WiX toolkit installed)

Additionally some general tricks exist:

  1. Launch the setup.exe and look in the system's temp folder for extracted files.
  2. Another trick is to use 7-Zip, WinRAR, WinZip or similar archive tools to see if they can read the setup.exe format.
  3. Some claim success by opening the setup.exe in Visual Studio. Not a technique I use.
  4. The general approach for finding switches is to open a command prompt and go setup.exe /? or setup.exe /help or similar.
  5. Also check for vendor online information and sites such as https://www.itninja.com/software.

A sprawling answer on this topic: Extract MSI from EXE.

If you manage to extract (or the file format is viewable as an archive), you can look for PDF, HTML, TXT or CHM files with further deployment info. Samples: ReadMe.txt, LSD.pdf, Large Scale Deployment.pdf, User Guide.chm, Manual.chm etc...


MSI - Customize Standard Package:

So, if the extract works and you extract an MSI file, then you can customize its installation in detail using standardized mechanisms. Make sure to look for the files with deployment information mentioned above - PDFs, CHMs, TXTs, etc... They could feature sample command lines for you to use more or less directly.

And crucially you could have extracted runtimes and prerequisites that also need to be deployed (.NET framework, Crystal Reports, Visual C++ Runtime, etc...). These are all managed and controlled on corporate networks and are not to be deployed with your package, but by their standardized packages.

Standardized customization mechanisms are great for corporate deployment, but require some MSI knowledge:

  • How to make better use of MSI files - a comprehensive description of MSI installation customization: with some sample command lines and description of the process.

  • A simplified view of MSI installation customization.

    • Here you can see that some setup.exe files can be installed directly in silent mode by passing in a command line using the /v parameter. These are Installshield MSI setups.

    • You can also see how the features in the MSI can be set at the command line.

A couple of concrete samples (extracted from links above):

  1. Command Line Customization

     msiexec.exe /i myinstaller.msi ADDLOCAL="Program,Dictionaries" SERIALKEY="1234-1234" /qn
    

    ADDLOCAL specifies what features from the MSI to install (see feature sample screenshot here). The uppercase values such as SERIALKEY are PUBLIC properties that can be set on the command line. These vary from setup to setup. Look for documentation from vendor, check the Property table and check the setup dialogs.

  2. Transform

     msiexec.exe /i myinstaller.msi TRANSFORMS="mytransform.mst" /qn
    

    The transform approach sets all the values needed inside a little file that is applied at installation time. It is called the transform. It is a little database fragment which is merged with the original MSI database at runtime.


Repackaging:

One way to create an MSI package from older-style, legacy setup.exe installers, is to "capture" the changes done to the system by using an Application Repackaging Tool which monitors changes made to the system whilst a setup.exe is being run.

This task may look easy, but it isn't. In fact it is very hard to clean up the resulting captures so you don't create "loose cannon" MSI files that cause problems on desktops throughout your organization. Corporations have dedicated teams to do this job and excellent MSI files can result that cause no problems when installed silently.

This task is not for the causal user in my opinion. It requires investment in the technology, expertise and time. Besides the tools available are pricey.


Silent Installation:

Most setup.exe files will at least attempt to install silently, though there are no guarantees. It is entirely possible that the setup.exe is impossible to install silently. I have seen it many times. In these cases repackaging is necessary, but even repackaging can fail at times. This is when it is time to push back on the vendor and ask them to get a grip about deployment. In a corporate world the software should be kicked head-first out of the application estate - if things work as they should.

Here is an old site dealing with the overall issue of silent installation of various setup.exe files: http://unattended.sourceforge.net/installers.php.

Here is a piece on silent uninstall which also describes silent running in general: Uninstall and Install App on my Computer silently

The general approach for finding such switches is to go setup.exe /? like you did. Often you can get a setup to install silently by trying something like this:

  • Visit https://www.itninja.com/software to check for switches from the community.
  • As stated above look for PDF, HTML, TXT or CHM files with further deployment info. Samples: ReadMe.txt, LSD.pdf, Large Scale Deployment.pdf, User Guide.chm, Manual.chm, etc...
  • Common: setup.exe /S, setup.exe /Q, setup.exe /quiet, setup.exe /VERYSILENT /NORESTART or similar.
  • Old-style Installshield setups need to have a response file recorded and then you install on all systems using the recorded dialog responses.

  • <

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...