Why is "msiexec /qn" still showing a command prompt ?
Categories:
Understanding and Suppressing the Command Prompt with MSIEXEC /QN

Explore why msiexec /qn
might still display a command prompt and learn effective strategies to achieve truly silent Windows Installer (MSI) installations, covering common pitfalls and solutions.
Windows Installer (MSI) packages are a common method for deploying software on Windows systems. The msiexec
command-line utility is used to manage these installations. A frequent requirement for automated deployments or unattended installations is to run the MSI silently, without any user interaction or visible windows. The /qn
switch is specifically designed for this purpose, indicating a 'no UI' or 'quiet' installation. However, many users encounter a perplexing issue: even with /qn
specified, a command prompt window briefly (or sometimes persistently) appears during the installation process. This article delves into the reasons behind this behavior and provides solutions to achieve a genuinely silent installation.
The Role of MSIEXEC /QN and Common Misconceptions
The /qn
switch instructs msiexec
to run the installation with no user interface. This means no progress bars, no dialog boxes, and no completion messages should be visible to the end-user. It's the cornerstone of silent deployments. However, the appearance of a command prompt window often leads to confusion, as it contradicts the expectation of a 'quiet' installation.
This behavior is typically not a bug in msiexec
itself, but rather a consequence of how the installation is invoked or what the MSI package itself is designed to do. Understanding the execution context is crucial.
flowchart TD A[Start Installation] --> B{Invoked via CMD/Script?} B -- Yes --> C[CMD Window Appears] B -- No --> D[Directly via API/Service] C --> E{MSI Package Actions?} D --> E E -- Custom Actions (EXE/BAT) --> F[New CMD Window] E -- No External Calls --> G[Truly Silent] F --> H[Installation Continues] G --> H H --> I[End Installation]
Flowchart illustrating potential reasons for command prompt visibility during MSI installation.
Root Causes for Command Prompt Visibility
There are several primary reasons why a command prompt might appear even with the /qn
switch:
Invocation Method: If you're running
msiexec
directly from a command prompt or a batch file (.bat
,.cmd
), the parent process (the command prompt itself) will remain visible untilmsiexec
completes. Whilemsiexec
might run silently, the window it was launched from is still there.Custom Actions in the MSI: Many MSI packages include custom actions that execute external programs or scripts (e.g.,
.exe
,.bat
,.vbs
,.ps1
) during the installation process. If these custom actions are not designed to run silently or are invoked incorrectly, they can spawn their own visible command prompt windows.Embedded Installers (Bootstrappers): Some software uses a bootstrapper executable that wraps the actual MSI. This bootstrapper might extract the MSI and then launch
msiexec
. If the bootstrapper itself isn't silent or doesn't correctly pass the/qn
flag tomsiexec
in a hidden window, a command prompt can appear.NSIS (Nullsoft Scriptable Install System) Installers: While NSIS is not MSI, it's often used for Windows installations. If an NSIS installer is configured to run an external command or another installer, and that command is not executed silently, a command prompt will appear. The
/S
switch is typically used for silent NSIS installations, but like MSI, custom actions within the NSIS script can still cause issues.
Achieving Truly Silent Installations
To ensure a genuinely silent installation without any visible command prompts, you need to address both the invocation method and the behavior of the MSI package itself.
1. Use start /wait
for Batch Files
When running msiexec
from a batch file, use start /wait
to launch msiexec
in a new, hidden window. This ensures the batch file waits for the installation to complete without keeping the original command prompt visible for the msiexec
process itself. Note that this doesn't hide custom actions that spawn their own windows.
2. Invoke via WScript.Shell
or PowerShell
For more robust silent execution, especially for custom actions or when running from a script, use WScript.Shell.Run
with the 0
parameter for intWindowStyle
(hidden window) or PowerShell's Start-Process
with -WindowStyle Hidden
.
3. Analyze MSI Custom Actions
If a command prompt still appears, the issue is likely within the MSI's custom actions. Use tools like Orca (from the Windows SDK) or InstEd to inspect the MSI package. Look for custom actions that execute .exe
or .bat
files. You might need to modify the MSI (if allowed and you have the expertise) or contact the vendor for a truly silent version of their custom actions.
4. Ensure Custom Actions are Silent
If you are creating the MSI or the custom actions, ensure that any external executables or scripts launched by custom actions are themselves silent. For example, if a custom action runs setup.exe
, ensure setup.exe
also accepts a silent switch (e.g., /S
, /qn
).
5. Use msiexec /i <package.msi> /qn /norestart
The /norestart
switch is often useful in silent installations to prevent the system from rebooting automatically after the installation, giving you control over when the restart occurs.
Batch File (CMD)
@echo off start "" /wait msiexec /i "C:\Path\To\Your\Installer.msi" /qn /L*v "C:\Path\To\Your\Install.log" exit /b %errorlevel%
PowerShell
$msiPath = "C:\Path\To\Your\Installer.msi"
$logPath = "C:\Path\To\Your\Install.log"
$arguments = "/i "$msiPath
" /qn /L*v "$logPath
" /norestart"
Start-Process -FilePath "msiexec.exe" -ArgumentList $arguments -Wait -WindowStyle Hidden -PassThru | Out-Null
VBScript
Set oShell = CreateObject("WScript.Shell") msiPath = "C:\Path\To\Your\Installer.msi" logPath = "C:\Path\To\Your\Install.log" command = "msiexec /i " & Chr(34) & msiPath & Chr(34) & " /qn /L*v " & Chr(34) & logPath & Chr(34) & " /norestart"
' Run the command hidden (0) and wait for completion (True) oShell.Run command, 0, True