MsiExecArguments.h (2790B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <list> 5 #include <string_view> 6 #include <vector> 7 8 9 // This file defines parsing of the command line arguments passed to msiexec.exe. 10 // 11 // Some packages require the UAC prompt for installing even on silent installs. This 12 // can be done with the MSI API using the INSTALLUILEVEL_UACONLY flag, but msiexec.exe 13 // does not provide a way to use it. So, we use the MSI API directly instead of 14 // through msiexec.exe. Since msiexec.exe does some parsing of command line arguments 15 // before handing off to the API, we replicate that parsing here. 16 // 17 // Since we care only about installation, we simplify the parsing by assuming that 18 // the command line has the form 19 // msiexec.exe /i (MSI file) [Other args...] 20 21 namespace AppInstaller::Msi 22 { 23 DEFINE_ENUM_FLAG_OPERATORS(INSTALLUILEVEL); 24 DEFINE_ENUM_FLAG_OPERATORS(INSTALLLOGMODE); 25 DEFINE_ENUM_FLAG_OPERATORS(INSTALLLOGATTRIBUTES); 26 27 constexpr INSTALLLOGMODE DefaultLogMode = 28 INSTALLLOGMODE_FATALEXIT | INSTALLLOGMODE_ERROR | INSTALLLOGMODE_WARNING | INSTALLLOGMODE_INFO | 29 INSTALLLOGMODE_OUTOFDISKSPACE | INSTALLLOGMODE_ACTIONSTART | INSTALLLOGMODE_ACTIONDATA; 30 31 // All but the four flags that always have to be set explicitly (Verbose, ExtraDebug, LogOnlyOnError, LogPerformance) 32 constexpr INSTALLLOGMODE AllLogMode = 33 INSTALLLOGMODE_FATALEXIT | INSTALLLOGMODE_ERROR | INSTALLLOGMODE_WARNING | INSTALLLOGMODE_USER | INSTALLLOGMODE_INFO | 34 INSTALLLOGMODE_OUTOFDISKSPACE | INSTALLLOGMODE_ACTIONSTART | INSTALLLOGMODE_ACTIONDATA | 35 INSTALLLOGMODE_PROPERTYDUMP | INSTALLLOGMODE_COMMONDATA; 36 37 // Arguments parsed from a command line string. 38 // Arguments currently supported are: 39 // - Logging options (/l) 40 // - Quiet options (/q) 41 // - Properties (PROPERTY=Value) 42 struct MsiParsedArguments 43 { 44 // Logging options. See: MsiEnableLog() 45 INSTALLLOGMODE LogMode = {}; 46 std::optional<std::wstring> LogFile; 47 INSTALLLOGATTRIBUTES LogAttributes = {}; 48 49 // UI options. See: MsiSetInternalUI() 50 INSTALLUILEVEL UILevel = INSTALLUILEVEL_DEFAULT; 51 52 // Properties string 53 std::wstring Properties; 54 }; 55 56 // Parses a command line string for msiexec. 57 // This function assumes that the full command line will have the form 58 // msiexec.exe /i package.msi [arguments] 59 // and that it is only parsing the [arguments] part. 60 // 61 // Note: This does not match msiexec exactly. It does not support options 62 // unrelated to install, nor all options for install (e.g. /n). 63 MsiParsedArguments ParseMSIArguments(std::string_view arguments); 64 }