using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; namespace Vanara.PInvoke { /// Items from the Msi.dll public static partial class Msi { /// The maximum characters in a feature name, not including the null-terminator. public const int MAX_FEATURE_CHARS = 38; /// The maximum characters in a GUID buffer, not including the null-terminator. public const int MAX_GUID_CHARS = 38; /// /// The INSTALLUI_HANDLER function prototype defines a callback function that the installer calls for progress notification /// and error messages. For more information on the usage of this function prototype, a sample code snippet is available in Handling /// Progress Messages Using MsiSetExternalUI. /// /// /// Pointer to an application context passed to the MsiSetExternalUI function. This parameter can be used for error checking. /// /// /// /// Specifies a combination of one message box style, one message box icon type, one default button, and one installation message /// type. This parameter must be one of the following. /// /// /// /// Message box StylesFlag /// Meaning /// /// /// MB_ABORTRETRYIGNORE /// The message box contains the Abort, Retry, and Ignore buttons. /// /// /// MB_OK /// The message box contains the OK button. This is the default. /// /// /// MB_OKCANCEL /// The message box contains the OK and Cancel buttons. /// /// /// MB_RETRYCANCEL /// The message box contains the Retry and Cancel buttons. /// /// /// MB_YESNO /// The message box contains the Yes and No buttons. /// /// /// MB_YESNOCANCEL /// The message box contains the Yes, No, and Cancel buttons. /// /// /// /// /// Message box IconTypesFlag /// Meaning /// /// /// MB_ICONEXCLAMATION, MB_ICONWARNING /// An exclamation point appears in the message box. /// /// /// MB_ICONINFORMATION, MB_ICONASTERISK /// The information sign appears in the message box. /// /// /// MB_ICONQUESTION /// A question mark appears in the message box. /// /// /// MB_ICONSTOP, MB_ICONERROR, MB_ICONHAND /// A stop sign appears in the message box. /// /// /// /// /// Default ButtonsFlag /// Meaning /// /// /// MB_DEFBUTTON1 /// The first button is the default button. /// /// /// MB_DEFBUTTON2 /// The second button is the default button. /// /// /// MB_DEFBUTTON3 /// The third button is the default button. /// /// /// /// /// Install message TypesFlag /// Meaning /// /// /// INSTALLMESSAGE_FATALEXIT /// Premature termination /// /// /// INSTALLMESSAGE_ERROR /// Formatted error message /// /// /// INSTALLMESSAGE_WARNING /// Formatted warning message /// /// /// INSTALLMESSAGE_USER /// User request message. /// /// /// INSTALLMESSAGE_INFO /// Informative message for log /// /// /// INSTALLMESSAGE_FILESINUSE /// List of files currently in use that must be closed before being replaced. /// /// /// INSTALLMESSAGE_RESOLVESOURCE /// Request to determine a valid source location /// /// /// INSTALLMESSAGE_RMFILESINUSE /// /// List of files currently in use that must be closed before being replaced. Available beginning with Windows Installer 4.0. For /// more information about this message see Using Restart Manager with an External UI. /// /// /// /// INSTALLMESSAGE_OUTOFDISKSPACE /// Insufficient disk space message /// /// /// INSTALLMESSAGE_ACTIONSTART /// Start of action message. This message includes the action name and description. /// /// /// INSTALLMESSAGE_ACTIONDATA /// Formatted data associated with the individual action item. /// /// /// INSTALLMESSAGE_PROGRESS /// Progress gauge information. This message includes information on units so far and total number of units. /// /// /// INSTALLMESSAGE_COMMONDATA /// Formatted dialog information for user interface. /// /// /// INSTALLMESSAGE_INITIALIZE /// Sent prior to UI initialization, no string data /// /// /// INSTALLMESSAGE_TERMINATE /// Sent after UI termination, no string data /// /// /// INSTALLMESSAGE_SHOWDIALOG /// Sent prior to display of authored dialog or wizard /// /// /// INSTALLMESSAGE_INSTALLSTART /// Sent prior to installation of product. /// /// /// INSTALLMESSAGE_INSTALLEND /// Sent after installation of product. /// /// /// /// The following defaults should be used if any of the preceding messages are missing: MB_OK, no icon, and MB_DEFBUTTON1. There is /// no default installation message type; a message type is always specified. /// /// /// Specifies the message text. /// /// The following return values map to the buttons specified by the message box style: /// IDOKIDCANCELIDABORTIDRETRYIDIGNOREIDYESIDNO /// /// /// For more information on returning values from an external user interface handler, see the Returning Values from an External User /// Interface Handler topic. /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nc-msi-installui_handlera INSTALLUI_HANDLERA InstalluiHandlera; int // InstalluiHandlera( LPVOID pvContext, UINT iMessageType, LPCSTR szMessage ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NC:msi.INSTALLUI_HANDLERA")] public delegate int INSTALLUI_HANDLER(IntPtr pvContext, uint iMessageType, [MarshalAs(UnmanagedType.LPTStr)] string szMessage); /// /// /// The INSTALLUI_HANDLER_RECORD function prototype defines a callback function that the installer calls for progress /// notification and error messages. Call the MsiSetExternalUIRecord function to enable a record-base external user-interface /// (UI) handler. /// /// /// Windows Installer 3.0 and Windows Installer 2.0: Not supported. Available beginning with Windows Installer version 3.1 /// and later. /// /// /// /// Pointer to an application context passed to the MsiSetExternalUIRecord function. This parameter can be used for error checking. /// /// /// /// Specifies a combination of one message box style, one message box icon type, one default button, and one installation message /// type. This parameter must be one of the following. /// /// /// /// Message box StylesFlag /// Meaning /// /// /// MB_ABORTRETRYIGNORE /// The message box contains the Abort, Retry, and Ignore buttons. /// /// /// MB_OK /// The message box contains the OK button. This is the default. /// /// /// MB_OKCANCEL /// The message box contains the OK and Cancel buttons. /// /// /// MB_RETRYCANCEL /// The message box contains the Retry and Cancel buttons. /// /// /// MB_YESNO /// The message box contains the Yes and No buttons. /// /// /// MB_YESNOCANCEL /// The message box contains the Yes, No, and Cancel buttons. /// /// /// /// /// Message box IconTypesFlag /// Meaning /// /// /// MB_ICONEXCLAMATION, MB_ICONWARNING /// An exclamation point appears in the message box. /// /// /// MB_ICONINFORMATION, MB_ICONASTERISK /// The information sign appears in the message box. /// /// /// MB_ICONQUESTION /// A question mark appears in the message box. /// /// /// MB_ICONSTOP, MB_ICONERROR, MB_ICONHAND /// A stop sign appears in the message box. /// /// /// /// /// Default ButtonsFlag /// Meaning /// /// /// MB_DEFBUTTON1 /// The first button is the default button. /// /// /// MB_DEFBUTTON2 /// The second button is the default button. /// /// /// MB_DEFBUTTON3 /// The third button is the default button. /// /// /// /// /// Install message TypesFlag /// Meaning /// /// /// INSTALLMESSAGE_FATALEXIT /// Premature termination /// /// /// INSTALLMESSAGE_ERROR /// Formatted error message /// /// /// INSTALLMESSAGE_WARNING /// Formatted warning message /// /// /// INSTALLMESSAGE_USER /// User request message. /// /// /// INSTALLMESSAGE_INFO /// Informative message for log /// /// /// INSTALLMESSAGE_FILESINUSE /// List of files currently in use that must be closed before being replaced /// /// /// INSTALLMESSAGE_RESOLVESOURCE /// Request to determine a valid source location /// /// /// INSTALLMESSAGE_RMFILESINUSE /// /// List of files currently in use that must be closed before being replaced. Available beginning with Windows Installer version /// 4.0. For more information about this message see Using Restart Manager with an External UI. /// /// /// /// INSTALLMESSAGE_OUTOFDISKSPACE /// Insufficient disk space message /// /// /// INSTALLMESSAGE_ACTIONSTART /// Start of action message. This message includes the action name and description. /// /// /// INSTALLMESSAGE_ACTIONDATA /// Formatted data associated with the individual action item. /// /// /// INSTALLMESSAGE_PROGRESS /// Progress gauge information. This message includes information on units so far and total number of units. /// /// /// INSTALLMESSAGE_COMMONDATA /// Formatted dialog information for user interface. /// /// /// INSTALLMESSAGE_INITIALIZE /// Sent prior to UI initialization, no string data /// /// /// INSTALLMESSAGE_TERMINATE /// Sent after UI termination, no string data /// /// /// INSTALLMESSAGE_SHOWDIALOG /// Sent prior to display of authored dialog or wizard /// /// /// INSTALLMESSAGE_INSTALLSTART /// Sent prior to installation of product. /// /// /// INSTALLMESSAGE_INSTALLEND /// Sent after installation of product. /// /// /// /// The following defaults should be used if any of the preceding messages are missing: MB_OK, no icon, and MB_DEFBUTTON1. There is /// no default installation message type; a message type is always specified. /// /// /// /// Specifies a handle to the record object. For information about record objects, see the Record Processing Functions. /// /// /// The following return values map to the buttons specified by the message box style: /// IDOKIDCANCELIDABORTIDRETRYIDIGNOREIDYESIDNO /// /// /// /// This type of external UI handler should be used when it is known what type of errors or messages the caller is interested in, /// and wants to avoid the overhead of parsing the string message that is sent to an external UI handler of INSTALLUI_HANDLER type, /// but retrieve the data of interest from fields of hRecord. /// /// /// For more information on returning values from an external user interface handler, see the Returning Values from an External User /// Interface Handler topic. The hRecord object sent to the record-based external UI handler is owned by Windows Installer and is /// valid only for the callback's lifetime. The callback should extract from the record any data it needs and it should not close /// that handle. /// /// Any attempt by a record-based external UI handler to alter the data in the hRecord object will be ignored by Windows Installer. /// For more information about using a record-based external handler, see Monitoring an Installation Using MsiSetExternalUIRecord. /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nc-msi-installui_handler_record INSTALLUI_HANDLER_RECORD // InstalluiHandlerRecord; int InstalluiHandlerRecord( LPVOID pvContext, UINT iMessageType, MSIHANDLE hRecord ) {...} [PInvokeData("msi.h", MSDNShortId = "NC:msi.INSTALLUI_HANDLER_RECORD")] [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate int INSTALLUI_HANDLER_RECORD(IntPtr pvContext, uint iMessageType, MSIHANDLE hRecord); /// /// The MsiAdvertiseProduct function generates an advertise script or advertises a product to the computer. The /// MsiAdvertiseProduct function enables the installer to write to a script the registry and shortcut information used to /// assign or publish a product. The script can be written to be consistent with a specified platform by using MsiAdvertiseProductEx. /// /// The full path to the package of the product being advertised. /// /// /// The full path to script file that will be created with the advertise information. To advertise the product locally to the /// computer, set ADVERTISEFLAGS_MACHINEASSIGN or ADVERTISEFLAGS_USERASSIGN. /// /// /// /// Flag /// Meaning /// /// /// ADVERTISEFLAGS_MACHINEASSIGN 0 /// Set to advertise a per-machine installation of the product available to all users. /// /// /// ADVERTISEFLAGS_USERASSIGN 1 /// Set to advertise a per-user installation of the product available to a particular user. /// /// /// /// /// A semicolon-delimited list of transforms to be applied. The list of transforms can be prefixed with the @ or | character to /// specify the secure caching of transforms. The @ prefix specifies secure-at-source transforms and the | prefix indicates secure /// full path transforms. For more information, see Secured Transforms. This parameter may be null. /// /// The installation language to use if the source supports multiple languages. /// /// /// /// Value /// Meaning /// /// /// ERROR_SUCCESS /// The function completed successfully. /// /// /// An error relating to an action /// See Error Codes. /// /// /// Initialization Error /// An initialization error occurred. /// /// /// ERROR_CALL_NOT_IMPLEMENTED /// /// This error is returned if an attempt is made to generate an advertise script on any platform other than Windows 2000 or Windows /// XP. Advertisement to the local computer is supported on all platforms. /// /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msiadvertiseproducta UINT MsiAdvertiseProductA( LPCSTR // szPackagePath, LPCSTR szScriptfilePath, LPCSTR szTransforms, LANGID lgidLanguage ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiAdvertiseProductA")] public static extern Win32Error MsiAdvertiseProduct([MarshalAs(UnmanagedType.LPTStr)] string szPackagePath, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szScriptfilePath, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szTransforms, ushort lgidLanguage); /// /// The MsiAdvertiseProductEx function generates an advertise script or advertises a product to the computer. This function /// enables Windows Installer to write to a script the registry and shortcut information used to assign or publish a product. The /// script can be written to be consistent with a specified platform by using MsiAdvertiseProductEx. The /// MsiAdvertiseProductEx function provides the same functionality as MsiAdvertiseProduct. /// /// The full path to the package of the product being advertised. /// /// /// The full path to the script file to be created with the advertised information. To advertise the product locally to the /// computer, set ADVERTISEFLAGS_MACHINEASSIGN or ADVERTISEFLAGS_USERASSIGN. /// /// /// /// Flag /// Meaning /// /// /// ADVERTISEFLAGS_MACHINEASSIGN 0 /// Set to advertise a per-computer installation of the product available to all users. /// /// /// ADVERTISEFLAGS_USERASSIGN 1 /// Set to advertise a per-user installation of the product available to a particular user. /// /// /// /// /// A semicolon–delimited list of transforms to be applied. The list of transforms can be prefixed with the @ or | character to /// specify the secure caching of transforms. The @ prefix specifies secure-at-source transforms and the | prefix indicates secure /// full path–transforms. For more information, see Secured Transforms. This parameter may be null. /// /// The language to use if the source supports multiple languages. /// /// /// Bit flags that control for which platform the installer should create the script. This parameter is ignored if szScriptfilePath /// is null. If dwPlatform is zero (0), then the script is created based on the current platform. This is the same functionality as /// MsiAdvertiseProduct. If dwPlatform is 1 or 2, the installer creates script for the specified platform. /// /// /// /// Flag /// Meaning /// /// /// none 0 /// Creates a script for the current platform. /// /// /// MSIARCHITECTUREFLAGS_X86 1 /// Creates a script for the x86 platform. /// /// /// MSIARCHITECTUREFLAGS_IA64 2 /// Creates a script for Itanium-based systems. /// /// /// MSIARCHITECTUREFLAGS_AMD64 4 /// Creates a script for the x64 platform. /// /// /// /// /// /// Bit flags that specify extra advertisement options. Nonzero value is only available in Windows Installer versions shipped with /// Windows Server 2003 and Windows XP with SP1 and later. /// /// /// /// Flag /// Meaning /// /// /// MSIADVERTISEOPTIONS_INSTANCE 1 /// /// Multiple instances through product code changing transform support flag. Advertises a new instance of the product. Requires that /// the szTransforms parameter includes the instance transform that changes the product code. For more information, see Installing /// Multiple Instances of Products and Patches. /// /// /// /// /// /// /// /// Value /// Meaning /// /// /// ERROR_SUCCESS /// The function completes successfully. /// /// /// An error that relates to an action /// For more information, see Error Codes. /// /// /// Initialization Error /// An initialization error has occurred. /// /// /// ERROR_CALL_NOT_IMPLEMENTED /// /// This error is returned if an attempt is made to generate an advertise script on any platform other than Windows 2000 or Windows /// XP. Advertisement to the local computer is supported on all platforms. /// /// /// /// /// /// Multiple instances through product code–changing transforms is only available for Windows Installer versions shipping with /// Windows Server 2003 and Windows XP with SP1 and later. /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msiadvertiseproductexa UINT MsiAdvertiseProductExA( LPCSTR // szPackagePath, LPCSTR szScriptfilePath, LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiAdvertiseProductExA")] public static extern Win32Error MsiAdvertiseProductEx([MarshalAs(UnmanagedType.LPTStr)] string szPackagePath, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szScriptfilePath, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szTransforms, ushort lgidLanguage, MSIARCHITECTUREFLAGS dwPlatform, MSIADVERTISEOPTIONFLAGS dwOptions); /// The MsiAdvertiseScript function copies an advertised script file into the specified locations. /// The full path to a script file generated by MsiAdvertiseProduct or MsiAdvertiseProductEx. /// /// /// The following bit flags from SCRIPTFLAGS control advertisement. The value of dwFlags can be a combination of the following values. /// /// /// /// Flag /// Meaning /// /// /// SCRIPTFLAGS_CACHEINFO 0x001 /// Include this flag if the icons need to be created or removed. /// /// /// SCRIPTFLAGS_SHORTCUTS 0x004 /// Include this flag if the shortcuts need to be created or removed. /// /// /// SCRIPTFLAGS_MACHINEASSIGN 0x008 /// Include this flag if the product to be assigned to a computer. /// /// /// SCRIPTFLAGS_REGDATA_CNFGINFO 0x020 /// Include this flag if the configuration and management information in the registry data needs to be written or removed. /// /// /// SCRIPTFLAGS_VALIDATE_TRANSFORMS_LIST 0x040 /// /// Include this flag to force validation of the transforms listed in the script against previously registered transforms for this /// product. Note that transform conflicts are detected using a string comparison that is case insensitive and are evaluated between /// per-user and per-machine installations across all contexts. If the list of transforms in the script does not match the /// transforms registered for the product, the function returns ERROR_INSTALL_TRANSFORM_FAILURE. /// /// /// /// SCRIPTFLAGS_REGDATA_CLASSINFO 0x080 /// Include this flag if advertisement information in the registry related to COM classes needs to be written or removed. /// /// /// SCRIPTFLAGS_REGDATA_EXTENSIONINFO 0x100 /// Include this flag if advertisement information in the registry related to an extension needs to be written or removed. /// /// /// SCRIPTFLAGS_REGDATA_APPINFO 0x180 /// Include this flag if the advertisement information in the registry needs to be written or removed. /// /// /// SCRIPTFLAGS_REGDATA 0x1A0 /// Include this flag if the advertisement information in the registry needs to be written or removed. /// /// /// /// /// /// A registry key under which temporary information about registry data is to be written. If this parameter is null, the registry /// data is placed under the appropriate key, based on whether the advertisement is per-user or per-machine. If this parameter is /// non-null, the script will write the registry data under the specified registry key rather than the normal location. In this /// case, the application will not get advertised to the user. /// /// /// Note that this registry key cannot be used when generating an advertisement of a product for a user or a computer because the /// provider of the registry key generally deletes the key. The registry key is located outside of the normal registry locations for /// shell, class, and .msi configuration information and it is not under HKEY_CLASSES_ROOT. This registry key is only /// intended for getting temporary information about registry data in a script. /// /// /// TRUE if specified items are to be removed instead of being created. /// /// /// /// Value /// Meaning /// /// /// ERROR_SUCCESS /// The function completed successfully. /// /// /// ERROR_ACCESS_DENIED /// The calling process was not running under the LocalSystem account. /// /// /// An error relating to an action /// See Error Codes. /// /// /// Initialization Error /// An error relating to initialization occurred. /// /// /// ERROR_CALL_NOT_IMPLEMENTED /// This function is only available on Windows 2000 and Windows XP. /// /// /// /// /// The process calling this function must be running under the LocalSystem account. To advertise an application for per-user /// installation to a targeted user, the thread that calls this function must impersonate the targeted user. If the thread calling /// this function is not impersonating a targeted user, the application is advertised to all users for installation with elevated privileges. /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msiadvertisescripta UINT MsiAdvertiseScriptA( LPCSTR szScriptFile, // DWORD dwFlags, PHKEY phRegData, BOOL fRemoveItems ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiAdvertiseScriptA")] public static extern Win32Error MsiAdvertiseScript([MarshalAs(UnmanagedType.LPTStr)] string szScriptFile, SCRIPTFLAGS dwFlags, [In, Optional] HKEY phRegData, [MarshalAs(UnmanagedType.Bool)] bool fRemoveItems); /// /// The MsiApplyMultiplePatches function applies one or more patches to products eligible to receive the patches. The /// MsiApplyMultiplePatches function sets the PATCH property with a list of patches delimited by semicolons and invokes the /// patching of the target products. Other properties can be set using a properties list. /// /// /// A semicolon-delimited list of the paths to patch files as a single string. For example: ""c:\sus\download\cache\Office\sp1.msp; /// c:\sus\download\cache\Office\QFE1.msp; c:\sus\download\cache\Office\QFEn.msp" " /// /// /// This parameter is the ProductCode GUID of the product to be patched. The user or application calling /// MsiApplyMultiplePatches must have privileges to apply patches. When this parameter is NULL, the patches are /// applied to all eligible products. When this parameter is non- NULL, the patches are applied only to the specified product. /// /// /// /// A null-terminated string that specifies command–line property settings used during the patching of products. If there are no /// command–line property settings, pass in a NULL pointer. An empty string is an invalid parameter. These properties are /// shared by all target products. For more information, see About Properties and Setting Public Property Values on the Command Line. /// /// /// Note The properties list should not contain the PATCH property. If the PATCH property is set in the command line /// the value is ignored and is overwritten with the patches being applied. /// /// /// /// The MsiApplyMultiplePatches function returns the following values. /// /// /// Value /// Meaning /// /// /// ERROR_INVALID_PARAMETER /// Some arguments passed in are incorrect or contradicting. /// /// /// ERROR_SUCCESS /// /// The function completed and all products are successfully patched. ERROR_SUCCESS is returned only if all the products eligible /// for the patches are patched successfully. If none of the new patches are applicable, MsiApplyMultiplePatches returns /// ERROR_SUCCESS and product state remains unchanged. /// /// /// /// ERROR_SUCCESS_REBOOT_INITIATED /// /// The restart initiated by the last transaction terminated this call to MsiApplyMultiplePatches. All the target products may not /// have been patched. /// /// /// /// ERROR_SUCCESS_REBOOT_REQUIRED /// /// The restart required by the last transaction terminated this call to MsiApplyMultiplePatches. All target products may not have /// been patched. /// /// /// /// ERROR_PATCH_PACKAGE_OPEN_FAILED /// One of the patch packages provide could not be opened. /// /// /// ERROR_PATCH_PACKAGE_INVALID /// One of the patch packages provide is not a valid one. /// /// /// ERROR_PATCH_PACKAGE_UNSUPPORTED /// One of the patch packages is unsupported. /// /// /// Any error in Winerror.h /// Implies possible partial completion or that one or more transactions failed. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msiapplymultiplepatchesa UINT MsiApplyMultiplePatchesA( LPCSTR // szPatchPackages, LPCSTR szProductCode, LPCSTR szPropertiesList ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiApplyMultiplePatchesA")] public static extern Win32Error MsiApplyMultiplePatches([MarshalAs(UnmanagedType.LPTStr)] string szPatchPackages, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szProductCode, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szPropertiesList); /// /// For each product listed by the patch package as eligible to receive the patch, the MsiApplyPatch function invokes an /// installation and sets the PATCH property to the path of the patch package. /// /// A null-terminated string specifying the full path to the patch package. /// /// /// If eInstallType is set to INSTALLTYPE_NETWORK_IMAGE, this parameter is a null-terminated string that specifies a path to the /// product that is to be patched. The installer applies the patch to every eligible product listed in the patch package if /// szInstallPackage is set to null and eInstallType is set to INSTALLTYPE_DEFAULT. /// /// /// If eInstallType is INSTALLTYPE_SINGLE_INSTANCE, the installer applies the patch to the product specified by szInstallPackage. In /// this case, other eligible products listed in the patch package are ignored and the szInstallPackage parameter contains the /// null-terminated string representing the product code of the instance to patch. This type of installation requires the installer /// running Windows Server 2003 or Windows XP. /// /// /// /// This parameter specifies the type of installation to patch. /// /// /// Type of installation /// Meaning /// /// /// INSTALLTYPE_NETWORK_IMAGE /// /// Specifies an administrative installation. In this case, szInstallPackage must be set to a package path. A value of 1 for /// INSTALLTYPE_NETWORK_IMAGE sets this for an administrative installation. /// /// /// /// INSTALLTYPE_DEFAULT /// Searches system for products to patch. In this case, szInstallPackage must be 0. /// /// /// INSTALLTYPE_SINGLE_INSTANCE /// /// Patch the product specified by szInstallPackage. szInstallPackage is the product code of the instance to patch. This type of /// installation requires the installer running Windows Server 2003 or Windows XP with SP1. For more information see, Installing /// Multiple Instances of Products and Patches. /// /// /// /// /// /// A null-terminated string that specifies command line property settings. See About Properties and Setting Public Property Values /// on the Command Line. See the Remarks section. /// /// /// /// /// Value /// Meaning /// /// /// ERROR_SUCCESS /// The function completed successfully. /// /// /// ERROR_PATCH_PACKAGE_OPEN_FAILED /// Patch package could not be opened. /// /// /// ERROR_PATCH_PACKAGE_INVALID /// The patch package is invalid. /// /// /// ERROR_PATCH_PACKAGE_UNSUPPORTED /// The patch package is unsupported. /// /// /// An error relating to an action /// See Error Codes. /// /// /// Initialization Error /// An initialization error occurred. /// /// /// /// /// /// Because the list delimiter for transforms, sources, and patches is a semicolon, this character should not be used for file names /// or paths. /// /// /// Note You must set the REINSTALL property on the command line when applying a small update or minor upgrade patch. Without /// this property, the patch is registered on the system but cannot update files. For patches that do not use a Custom Action Type /// 51 to automatically set the REINSTALL and REINSTALLMODE properties, the REINSTALL property must be explicitly set /// with the szCommandLine parameter. Set the REINSTALL property to list the features affected by the patch, or use a /// practical default setting of "REINSTALL=ALL". The default value of the REINSTALLMODE property is "omus". Beginning with /// Windows Installer version 3.0, the REINSTALL property is configured by the installer and does not need to be set on the /// command line. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msiapplypatcha UINT MsiApplyPatchA( LPCSTR szPatchPackage, LPCSTR // szInstallPackage, INSTALLTYPE eInstallType, LPCSTR szCommandLine ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiApplyPatchA")] public static extern Win32Error MsiApplyPatch([MarshalAs(UnmanagedType.LPTStr)] string szPatchPackage, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szInstallPackage, INSTALLTYPE eInstallType, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szCommandLine); /// /// /// The MsiBeginTransaction function starts transaction processing of a multiple-package installation and returns an /// identifier for the transaction. The MsiEndTransaction function ends the transaction. /// /// Windows Installer 4.0 and earlier: Not supported. This function is available beginning with Windows Installer 4.5. /// /// Name of the multiple-package installation. /// /// Attributes of the multiple-package installation. /// /// /// Value /// Meaning /// /// /// 0 /// When 0 or no value is set it Windows Installer closes the UI from the previous installation. /// /// /// MSITRANSACTION_CHAIN_EMBEDDEDUI /// Set this attribute to request that the Windows Installer not shutdown the embedded UI until the transaction is complete. /// /// /// /// /// Transaction ID is a MSIHANDLE value that identifies the transaction. Only one process can own a transaction at a time. /// /// /// This parameter returns a handle to an event that is set when the MsiJoinTransaction function changes the owner of the /// transaction to a new owner. The current owner can use this to determine when ownership of the transaction has changed. Leaving a /// transaction without an owner will roll back the transaction. /// /// /// The MsiBeginTransaction function returns the following values. /// /// /// Value /// Meaning /// /// /// ERROR_INSTALL_SERVICE_FAILURE /// The installation service could not be accessed. This function requires the Windows Installer service. /// /// /// ERROR_INSTALL_ALREADY_RUNNING /// /// Only one transaction can be open on a system at a time. The function returns this error if called while another transaction is running. /// /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter is passed to the function. /// /// /// ERROR_ROLLBACK_DISABLED /// Rollback Installations have been disabled by the DISABLEROLLBACK property or DisableRollback policy. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msibegintransactiona UINT MsiBeginTransactionA( LPCSTR szName, // DWORD dwTransactionAttributes, MSIHANDLE *phTransactionHandle, HANDLE *phChangeOfOwnerEvent ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiBeginTransactionA")] public static extern Win32Error MsiBeginTransaction([MarshalAs(UnmanagedType.LPTStr)] string szName, MSITRANSACTION dwTransactionAttributes, out PMSIHANDLE phTransactionHandle, out System.Threading.EventWaitHandle phChangeOfOwnerEvent); /// /// The MsiCloseAllHandles function closes all open installation handles allocated by the current thread. This is a /// diagnostic function and should not be used for cleanup. /// /// /// This function returns 0 if all handles are closed. Otherwise, the function returns the number of handles open prior to its call. /// /// /// /// MsiCloseAllHandles only closes handles allocated by the calling thread, and does not affect handles allocated by other /// threads, such as the install handle passed to custom actions. /// /// /// The MsiOpenPackage function opens a handle to a package and the MsiOpenProduct function opens a handle to a product. These /// function are for use with functions that access the product database. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msicloseallhandles UINT MsiCloseAllHandles(); [DllImport(Lib_Msi, SetLastError = false, ExactSpelling = true)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiCloseAllHandles")] public static extern uint MsiCloseAllHandles(); /// The MsiCloseHandle function closes an open installation handle. /// Specifies any open installation handle. /// /// /// /// Value /// Meaning /// /// /// ERROR_INVALID_HANDLE /// An invalid handle was passed to the function. /// /// /// ERROR_SUCCESS /// The function succeeded. /// /// /// /// /// MsiCloseHandle must be called from the same thread that requested the creation of the handle. /// The following functions supply handles that should be closed after use by calling MsiCloseHandle: /// /// MsiCreateRecord MsiGetActiveDatabase MsiGetLastErrorRecord MsiOpenPackage MsiOpenProduct MsiOpenDatabase MsiDatabaseOpenView /// MsiViewFetch MsiViewGetColumnInfo MsiDatabaseGetPrimaryKeys MsiGetSummaryInformation MsiEnableUIPreview Note that when writing /// custom actions, it is recommended to use variables of type PMSIHANDLE because the installer closes PMSIHANDLE objects as they go /// out of scope, whereas you must close MSIHANDLE objects by calling MsiCloseHandle. /// /// For example, if you use code like this: /// MSIHANDLE hRec = MsiCreateRecord(3); /// Change it to: /// PMSIHANDLE hRec = MsiCreateRecord(3); /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msiclosehandle UINT MsiCloseHandle( MSIHANDLE hAny ); [DllImport(Lib_Msi, SetLastError = true, ExactSpelling = true)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiCloseHandle")] public static extern Win32Error MsiCloseHandle(MSIHANDLE hAny); /// /// The MsiCollectUserInfo function obtains and stores the user information and product ID from an installation wizard. /// /// Specifies the product code of the product for which the user information is collected. /// /// /// /// Value /// Meaning /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter was passed to the function. /// /// /// ERROR_SUCCESS /// The function succeeded. /// /// /// An error relating to an action /// See Error Codes. /// /// /// Initialization Error /// An error relating to initialization occurred. /// /// /// /// /// /// The MsiCollectUserInfo function is typically called by an application during the first run of the application. The /// application first calls MsiGetUserInfo. If that call fails, the application calls MsiCollectUserInfo. /// MsiCollectUserInfo opens the product's installation package and invokes a wizard sequence that collects user information. /// Upon completion of the sequence, user information is registered. Since this API requires an authored user interface, the user /// interface level should be set to full by calling MsiSetInternalUI as INSTALLUILEVEL_FULL. /// /// The MsiCollectUserInfo invokes a FirstRun Dialog. /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msicollectuserinfow UINT MsiCollectUserInfoW( LPCWSTR szProduct ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiCollectUserInfoW")] public static extern Win32Error MsiCollectUserInfo([MarshalAs(UnmanagedType.LPTStr)] string szProduct); /// The MsiConfigureFeature function configures the installed state for a product feature. /// Specifies the product code for the product to be configured. /// Specifies the feature ID for the feature to be configured. /// /// Specifies the installation state for the feature. This parameter must be one of the following values. /// /// /// Value /// Meaning /// /// /// INSTALLSTATE_ADVERTISED /// The feature is advertised /// /// /// INSTALLSTATE_LOCAL /// The feature is installed locally. /// /// /// INSTALLSTATE_ABSENT /// The feature is uninstalled. /// /// /// INSTALLSTATE_SOURCE /// The feature is installed to run from source. /// /// /// INSTALLSTATE_DEFAULT /// The feature is installed to its default location. /// /// /// /// /// /// /// Value /// Meaning /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter is passed to the function. /// /// /// ERROR_SUCCESS /// The function succeeds. /// /// /// An error relating to an action /// For more information, see Error Codes. /// /// /// Initialization Error /// An error that relates to the initialization has occurred. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msiconfigurefeaturew UINT MsiConfigureFeatureW( LPCWSTR szProduct, // LPCWSTR szFeature, INSTALLSTATE eInstallState ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiConfigureFeatureW")] public static extern Win32Error MsiConfigureFeature([MarshalAs(UnmanagedType.LPTStr)] string szProduct, [MarshalAs(UnmanagedType.LPTStr)] string szFeature, INSTALLSTATE eInstallState); /// The MsiConfigureProduct function installs or uninstalls a product. /// Specifies the product code for the product to be configured. /// /// /// Specifies how much of the product should be installed when installing the product to its default state. The iInstallLevel /// parameter is ignored, and all features are installed, if the eInstallState parameter is set to any other value than INSTALLSTATE_DEFAULT. /// /// This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// INSTALLLEVEL_DEFAULT /// The authored default features are installed. /// /// /// INSTALLLEVEL_MINIMUM /// /// Only the required features are installed. You can specify a value between INSTALLLEVEL_MINIMUM and INSTALLLEVEL_MAXIMUM to /// install a subset of available features. /// /// /// /// INSTALLLEVEL_MAXIMUM /// /// All features are installed. You can specify a value between INSTALLLEVEL_MINIMUM and INSTALLLEVEL_MAXIMUM to install a subset of /// available features. /// /// /// /// /// /// Specifies the installation state for the product. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// INSTALLSTATE_LOCAL /// The product is to be installed with all features installed locally. /// /// /// INSTALLSTATE_ABSENT /// The product is uninstalled. /// /// /// INSTALLSTATE_SOURCE /// The product is to be installed with all features installed to run from source. /// /// /// INSTALLSTATE_DEFAULT /// The product is to be installed with all features installed to the default states specified in the Feature Table. /// /// /// INSTALLSTATE_ADVERTISED /// The product is advertised. /// /// /// /// /// /// /// Value /// Meaning /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter is passed to the function. /// /// /// ERROR_SUCCESS /// The function succeeds. /// /// /// An error that relates to an action /// For more information, see Error Codes. /// /// /// Initialization Error /// An error that relates to initialization. /// /// /// /// /// /// The MsiConfigureProduct function displays the user interface (UI) using the current settings. User interface settings can /// be changed by using MsiSetInternalUI, MsiSetExternalUI or MsiSetExternalUIRecord. /// /// /// The iInstallLevel parameter is ignored, and all features of the product are installed, if the eInstallState parameter is set to /// any other value than INSTALLSTATE_DEFAULT. To control the installation of individual features when the eInstallState parameter /// is not set to INSTALLSTATE_DEFAULT, use MsiConfigureFeature. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msiconfigureproducta UINT MsiConfigureProductA( LPCSTR szProduct, // int iInstallLevel, INSTALLSTATE eInstallState ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiConfigureProductA")] public static extern Win32Error MsiConfigureProduct([MarshalAs(UnmanagedType.LPTStr)] string szProduct, INSTALLLEVEL iInstallLevel, INSTALLSTATE eInstallState); /// The MsiConfigureProductEx function installs or uninstalls a product. A product command line can also be specified. /// Specifies the product code for the product to be configured. /// /// /// Specifies how much of the product should be installed when installing the product to its default state. The iInstallLevel /// parameters are ignored, and all features are installed, if the eInstallState parameter is set to any value other than INSTALLSTATE_DEFAULT. /// /// This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// INSTALLLEVEL_DEFAULT /// The authored default features are installed. /// /// /// INSTALLLEVEL_MINIMUM /// /// Only the required features are installed. You can specify a value between INSTALLLEVEL_MINIMUM and INSTALLLEVEL_MAXIMUM to /// install a subset of available features. /// /// /// /// INSTALLLEVEL_MAXIMUM /// /// All features are installed. You can specify a value between INSTALLLEVEL_MINIMUM and INSTALLLEVEL_MAXIMUM to install a subset of /// available features. /// /// /// /// /// /// Specifies the installation state for the product. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// INSTALLSTATE_LOCAL /// The product is to be installed with all features installed locally. /// /// /// INSTALLSTATE_ABSENT /// The product is uninstalled. /// /// /// INSTALLSTATE_SOURCE /// The product is to be installed with all features installed to run from source. /// /// /// INSTALLSTATE_DEFAULT /// The product is to be installed with all features installed to the default states specified in the Feature Table. /// /// /// INSTALLSTATE_ADVERTISED /// The product is advertised. /// /// /// /// /// Specifies the command-line property settings. This should be a list of the format Property=Setting Property=Setting. For more /// information, see About Properties. /// /// /// /// /// Value /// Meaning /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter is passed to the function. /// /// /// ERROR_SUCCESS /// The function succeeded. /// /// /// An error that relates to an action /// For more information, see Error Codes. /// /// /// Initialization Error /// An error relating to initialization occurred. /// /// /// /// /// /// The command line passed in as szCommandLine can contain any of the Feature Installation Options Properties. In this case, the /// eInstallState passed must be INSTALLSTATE_DEFAULT. /// /// /// The iInstallLevel parameter is ignored and all features of the product are installed if the eInstallState parameter is set to /// any other value than INSTALLSTATE_DEFAULT. To control the installation of individual features when the eInstallState /// parameter is not set to INSTALLSTATE_DEFAULT use MsiConfigureFeature. /// /// /// The MsiConfigureProductEx function displays the user interface using the current settings. User interface settings can be /// changed with MsiSetInternalUI, MsiSetExternalUI, or MsiSetExternalUIRecord. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msiconfigureproductexa UINT MsiConfigureProductExA( LPCSTR // szProduct, int iInstallLevel, INSTALLSTATE eInstallState, LPCSTR szCommandLine ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiConfigureProductExA")] public static extern Win32Error MsiConfigureProductEx([MarshalAs(UnmanagedType.LPTStr)] string szProduct, INSTALLLEVEL iInstallLevel, INSTALLSTATE eInstallState, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szCommandLine); /// /// The MsiDetermineApplicablePatches function takes a set of patch files, XML files, and XML blobs and determines which /// patches apply to a specified Windows Installer package and in what sequence. The function can account for superseded or obsolete /// patches. This function does not account for products or patches that are installed on the system that are not specified in the set. /// /// /// Full path to an .msi file. The function determines the patches that are applicable to this package and in what sequence. /// /// Number of patches in the array. Must be greater than zero. /// Pointer to an array of MSIPATCHSEQUENCEINFO structures. /// /// The MsiDetermineApplicablePatches function returns the following values. /// /// /// Value /// Meaning /// /// /// ERROR_FUNCTION_FAILED /// The function failed in a manner not covered in the other error codes. /// /// /// ERROR_INVALID_PARAMETER /// An argument is invalid. /// /// /// ERROR_PATCH_NO_SEQUENCE /// No valid sequence could be found for the set of patches. /// /// /// ERROR_SUCCESS /// The patches were successfully sorted. /// /// /// ERROR_FILE_NOT_FOUND /// The .msi file was not found. /// /// /// ERROR_PATH_NOT_FOUND /// The path to the .msi file was not found. /// /// /// ERROR_INVALID_PATCH_XML /// The XML patch data is invalid. /// /// /// ERROR_INSTALL_PACKAGE_OPEN_FAILED /// An installation package referenced by path cannot be opened. /// /// /// ERROR_CALL_NOT_IMPLEMENTED /// This error can be returned if the function was called from a custom action or if MSXML 3.0 is not installed. /// /// /// /// /// /// If this function is called from a custom action it fails and returns ERROR_CALL_NOT_IMPLEMENTED. The function requires MSXML /// version 3.0 to process XML and returns ERROR_CALL_NOT_IMPLEMENTED if MSXML 3.0 is not installed. /// /// /// The MsiDetermineApplicablePatches function sets the uStatus and dwOrder members of each /// MSIPATCHSEQUENCEINFO structure pointed to by pPatchInfo. Each structure contains information about a particular patch. /// /// /// If the function succeeds, the MSIPATCHSEQUENCEINFO structure of every patch that can be applied to the product returns with a /// uStatus of ERROR_SUCCESS and a dwOrder greater than or equal to zero. The values of dwOrder greater than or /// equal to zero indicate the best application sequence for the patches starting with zero. /// /// /// If the function succeeds, patches excluded from the best patching sequence return a MSIPATCHSEQUENCEINFO structure with a /// dwOrder equal to -1. In these cases, a uStatus field of ERROR_SUCCESS indicates a patch that is obsolete or /// superseded for the product. A uStatus field of ERROR_PATCH_TARGET_NOT_FOUND indicates a patch that is inapplicable to the product. /// /// /// If the function fails, the MSIPATCHSEQUENCEINFO structure for every patch returns a dwOrder equal to -1. In this case, /// the uStatus fields can contain errors with more information about individual patches. For example, /// ERROR_PATCH_NO_SEQUENCE is returned for patches that have circular sequencing information. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msidetermineapplicablepatchesa UINT MsiDetermineApplicablePatchesA( // LPCSTR szProductPackagePath, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiDetermineApplicablePatchesA")] public static extern Win32Error MsiDetermineApplicablePatches([MarshalAs(UnmanagedType.LPTStr)] string szProductPackagePath, uint cPatchInfo, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] MSIPATCHSEQUENCEINFO[] pPatchInfo); /// /// The MsiDeterminePatchSequence function takes a set of patch files, XML files, and XML blobs and determines the best /// sequence of application for the patches to a specified installed product. This function accounts for patches that have already /// been applied to the product and accounts for obsolete and superseded patches. /// /// /// The product that is the target for the set of patches. The value must be the ProductCode GUID for the product. /// /// /// Null-terminated string that specifies a security identifier (SID) of a user. This parameter restricts the context of enumeration /// for this user account. This parameter cannot be the special SID strings "S-1-1-0" (everyone) or "S-1-5-18" (local system). For /// the machine context dwContext is set to MSIINSTALLCONTEXT_MACHINE and szUserSid must be NULL. For the current user /// context szUserSid can be null and dwContext can be set to MSIINSTALLCONTEXT_USERMANAGED or MSIINSTALLCONTEXT_USERUNMANAGED. /// /// /// /// Restricts the enumeration to a per-user-unmanaged, per-user-managed, or per-machine context. This parameter can be any one of /// the following values. /// /// /// /// Type of context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED /// /// Patches are considered for all per-user-managed installations of the product for the user specified by szUserSid. A null /// szUserSid with this context means the current user. /// /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED /// /// Patches are considered for all per-user-unmanaged installations for the user specified by szUserSid. A null szUserSid with this /// context means the current user. /// /// /// /// MSIINSTALLCONTEXT_MACHINE /// /// Patches are considered for the per-machine installation. When dwContext is set to MSIINSTALLCONTEXT_MACHINE the szUserSid /// parameter must be null. /// /// /// /// /// The number of patches in the array. /// Pointer to an array of MSIPATCHSEQUENCEINFO structures. /// /// The MsiDeterminePatchSequence function returns the following values. /// /// /// Value /// Meaning /// /// /// ERROR_FUNCTION_FAILED /// The function failed in a manner not covered in the other error codes. /// /// /// ERROR_INVALID_PARAMETER /// An argument is invalid. /// /// /// ERROR_PATCH_NO_SEQUENCE /// No valid sequence could be found for the set of patches. /// /// /// ERROR_INSTALL_PACKAGE_OPEN_FAILED /// An installation package referenced by path cannot be opened. /// /// /// ERROR_SUCCESS /// The patches were successfully sorted. /// /// /// ERROR_FILE_NOT_FOUND /// The .msi file was not found. /// /// /// ERROR_PATH_NOT_FOUND /// The path to the .msi file was not found. /// /// /// ERROR_INVALID_PATCH_XML /// The XML patch data is invalid. /// /// /// ERROR_INSTALL_PACKAGE_INVALID /// The installation package was invalid. /// /// /// ERROR_ACCESS_DENIED /// A user that is not an administrator attempted to call the function with a context of a different user. /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data for a registered patch or product is invalid. /// /// /// ERROR_UNKNOWN_PRODUCT /// The ProductCode GUID specified is not registered. /// /// /// ERROR_FUNCTION_NOT_CALLED /// /// Windows Installer version 3.0 is required to determine the best patch sequence. The function was called with szProductCode not /// yet installed with Windows Installer version 3.0. /// /// /// /// ERROR_CALL_NOT_IMPLEMENTED /// This error can be returned if the function was called from a custom action or if MSXML 3.0 is not installed. /// /// /// ERROR_UNKNOWN_PATCH /// The specified patch is unknown. /// /// /// /// /// /// Users that do not have administrator privileges can call this function only in their own or machine context. Users that are /// administrators can call it for other users. /// /// /// If this function is called from a custom action it fails and returns ERROR_CALL_NOT_IMPLEMENTED. The function requires /// MSXML version 3.0 to process XML and returns ERROR_CALL_NOT_IMPLEMENTED if MSXML 3.0 is not installed. /// /// /// The MsiDeterminePatchSequence function sets the uStatus and dwOrder members of each MSIPATCHSEQUENCEINFO /// structure pointed to by pPatchInfo. Each structure contains information about a particular patch. /// /// /// If the function succeeds, the MSIPATCHSEQUENCEINFO structure of every patch that can be applied to the product returns with a /// uStatus of ERROR_SUCCESS and a dwOrder greater than or equal to zero. The values of dwOrder greater /// than or equal to zero indicate the best application sequence for the patches starting with zero. /// /// /// If the function succeeds, patches excluded from the best patching sequence return a MSIPATCHSEQUENCEINFO structure with a /// dwOrder equal to -1. In these cases, a uStatus field of ERROR_SUCCESS indicates a patch that is obsolete or /// superseded for the product. A uStatus field of ERROR_PATCH_TARGET_NOT_FOUND indicates a patch that is inapplicable /// to the product. /// /// /// If the function fails, the MSIPATCHSEQUENCEINFO structure for every patch returns a dwOrder equal to -1. In this case, /// the uStatus fields can contain errors with more information about individual patches. For example, /// ERROR_PATCH_NO_SEQUENCE is returned for patches that have circular sequencing information. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msideterminepatchsequencea UINT MsiDeterminePatchSequenceA( LPCSTR // szProductCode, LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiDeterminePatchSequenceA")] public static extern Win32Error MsiDeterminePatchSequence([MarshalAs(UnmanagedType.LPTStr)] string szProductCode, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szUserSid, MSIINSTALLCONTEXT dwContext, uint cPatchInfo, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] MSIPATCHSEQUENCEINFO[] pPatchInfo); /// /// The MsiEnableLog function sets the log mode for all subsequent installations that are initiated in the calling process. /// /// /// Specifies the log mode. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// INSTALLLOGMODE_FATALEXIT /// Logs out of memory or fatal exit information. /// /// /// INSTALLLOGMODE_ERROR /// Logs the error messages. /// /// /// INSTALLLOGMODE_EXTRADEBUG /// /// Sends extra debugging information, such as handle creation information, to the log file. Windows 2000 and Windows XP: This /// feature is not supported. /// /// /// /// INSTALLLOGMODE_WARNING /// Logs the warning messages. /// /// /// INSTALLLOGMODE_USER /// Logs the user requests. /// /// /// INSTALLLOGMODE_INFO /// Logs the status messages that are not displayed. /// /// /// INSTALLLOGMODE_RESOLVESOURCE /// Request to determine a valid source location. /// /// /// INSTALLLOGMODE_OUTOFDISKSPACE /// Indicates insufficient disk space. /// /// /// INSTALLLOGMODE_ACTIONSTART /// Logs the start of new installation actions. /// /// /// INSTALLLOGMODE_ACTIONDATA /// Logs the data record with the installation action. /// /// /// INSTALLLOGMODE_COMMONDATA /// Logs the parameters for user-interface initialization. /// /// /// INSTALLLOGMODE_PROPERTYDUMP /// Logs the property values at termination. /// /// /// INSTALLLOGMODE_VERBOSE /// /// Logs the information in all the other log modes, except for INSTALLLOGMODE_EXTRADEBUG. This sends large amounts of information /// to a log file not generally useful to users. May be used for technical support. /// /// /// /// INSTALLLOGMODE_LOGONLYONERROR /// /// Logging information is collected but is is less frequently saved to the log file. This can improve the performance of some /// installations, but may have little benefit for large installations. The log file is removed when the installation succeeds. If /// the installation fails, all logging information is saved to the log file. Windows Installer 2.0: This log mode is not available. /// /// /// /// /// /// Specifies the string that holds the full path to the log file. Entering a null disables logging, in which case dwlogmode is /// ignored. If a path is supplied, then dwlogmode must not be zero. /// /// /// Specifies how frequently the log buffer is to be flushed. /// /// /// Value /// Meaning /// /// /// INSTALLLOGATTRIBUTES_APPEND /// /// If this value is set, the installer appends the existing log specified by szLogFile. If not set, any existing log specified by /// szLogFile is overwritten. /// /// /// /// INSTALLLOGATTRIBUTES_FLUSHEACHLINE /// /// Forces the log buffer to be flushed after each line. If this value is not set, the installer flushes the log buffer after 20 /// lines by calling FlushFileBuffers. /// /// /// /// /// /// /// /// Value /// Meaning /// /// /// ERROR_INVALID_PARAMETER /// An invalid log mode was specified. /// /// /// ERROR_SUCCESS /// The function succeeded. /// /// /// /// /// For a description of the Logging policy, see System Policy. /// /// The path to the log file location must already exist when using this function. The Installer does not create the directory /// structure for the log file. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienableloga UINT MsiEnableLogA( DWORD dwLogMode, LPCSTR // szLogFile, DWORD dwLogAttributes ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnableLogA")] public static extern Win32Error MsiEnableLog(INSTALLLOGMODE dwLogMode, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szLogFile, INSTALLLOGATTRIBUTES dwLogAttributes); /// /// /// The MsiEndTransaction function can commit or roll back all the installations belonging to the transaction opened by the /// MsiBeginTransaction function. This function should be called by the current owner of the transaction. /// /// Windows Installer 4.0 and earlier: Not supported. This function is available beginning with Windows Installer 4.5. /// /// /// /// The value of this parameter determines whether the installer commits or rolls back all the installations belonging to the /// transaction. The value can be one of the following. /// /// /// /// Value /// Meaning /// /// /// MSITRANSACTIONSTATE_ROLLBACK /// /// Performs a Rollback Installation to undo changes to the system belonging to the transaction opened by the MsiBeginTransaction function. /// /// /// /// MSITRANSACTIONSTATE_COMMIT /// /// Commits all changes to the system belonging to the transaction. Runs any Commit Custom Actions and commits to the system any /// changes to Win32 or common language runtime assemblies. Deletes the rollback script, and after using this option, the /// transaction's changes can no longer be undone with a Rollback Installation. /// /// /// /// /// /// The MsiEndTransaction function returns the following values. /// /// /// Value /// Meaning /// /// /// ERROR_ACCESS_DENIED /// A transaction can be ended only by the current owner. /// /// /// ERROR_INSTALL_FAILURE /// An installation belonging to the transaction could not be completed. /// /// /// ERROR_INSTALL_ALREADY_RUNNING /// An installation belonging to the transaction is still in progress. /// /// /// ERROR_ROLLBACK_DISABLED /// /// An installation belonging to the transaction did not complete. During the installation, the DisableRollback action disabled /// rollback installations of the package. The installer rolls back the installation up to the point where rollback was disabled, /// and the function returns this error. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msiendtransaction UINT MsiEndTransaction( DWORD dwTransactionState ); [DllImport(Lib_Msi, SetLastError = false, ExactSpelling = true)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEndTransaction")] public static extern Win32Error MsiEndTransaction(MSITRANSACTIONSTATE dwTransactionState); /// /// The MsiEnumClients function enumerates the clients for a given installed component. The function retrieves one product /// code each time it is called. /// /// Specifies the component whose clients are to be enumerated. /// /// Specifies the index of the client to retrieve. This parameter should be zero for the first call to the MsiEnumClients /// function and then incremented for subsequent calls. Because clients are not ordered, any new client has an arbitrary index. This /// means that the function can return clients in any order. /// /// /// Pointer to a buffer that receives the product code. This buffer must be 39 characters long. The first 38 characters are for the /// GUID, and the last character is for the terminating null character. /// /// /// /// /// Value /// Meaning /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter was passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no clients to return. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// The system does not have enough memory to complete the operation. Available with Windows Server 2003. /// /// /// ERROR_SUCCESS /// A value was enumerated. /// /// /// ERROR_UNKNOWN_COMPONENT /// The specified component is unknown. /// /// /// /// /// /// To enumerate clients, an application should initially call the MsiEnumClients function with the iProductIndex parameter /// set to zero. The application should then increment the iProductIndexparameter and call MsiEnumClients until there are no /// more clients (that is, until the function returns ERROR_NO_MORE_ITEMS). /// /// /// When making multiple calls to MsiEnumClients to enumerate all of the component's clients, each call should be made from /// the same thread. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumclientsa UINT MsiEnumClientsA( LPCSTR szComponent, DWORD // iProductIndex, LPSTR lpProductBuf ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumClientsA")] public static extern Win32Error MsiEnumClients([MarshalAs(UnmanagedType.LPTStr)] string szComponent, uint iProductIndex, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpProductBuf); /// /// /// The MsiEnumClientsEx function enumerates the installed applications that use a specified component. The function /// retrieves a product code for an application each time it is called. /// /// Windows Installer 4.5 or earlier: Not supported. This function is available beginning with Windows Installer 5.0. /// /// /// The component code GUID that identifies the component. The function enumerates the applications that use this component. /// /// /// /// A null-terminated string value that contains a security identifier (SID.) The enumeration of applications extends to users /// identified by this SID. The special SID string s-1-1-0 (Everyone) enumerates all applications for all users in the system. A SID /// value other than s-1-1-0 specifies a user SID for a particular user and enumerates the instances of applications installed by /// the specified user. /// /// /// /// SID type /// Meaning /// /// /// NULL /// Specifies the currently logged-on user. /// /// /// User SID /// Specifies an enumeration for a particular user. An example of an user SID is "S-1-3-64-2415071341-1358098788-3127455600-2561". /// /// /// s-1-1-0 /// Specifies an enumeration for all users in the system. /// /// /// /// Note The special SID string s-1-5-18 (System) cannot be used to enumerate applications that exist in the per-machine /// installation context. Setting the SID value to s-1-5-18 returns ERROR_INVALID_PARAMETER. When dwContext is set to /// MSIINSTALLCONTEXT_MACHINE only, the value of szUserSid must be NULL. /// /// /// /// /// A flag that extends the enumeration to instances of applications installed in the specified installation context. The /// enumeration includes only instances of applications that are installed by the users identified by szUserSid. /// /// This can be a combination of the following values. /// /// /// Context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED 1 /// Include applications installed in the per–user–managed installation context. /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED 2 /// Include applications installed in the per–user–unmanaged installation context. /// /// /// MSIINSTALLCONTEXT_MACHINE 4 /// /// Include applications installed in the per-machine installation context. When dwInstallContext is set to /// MSIINSTALLCONTEXT_MACHINE only, the value of the szUserSID parameter must be NULL. /// /// /// /// /// /// Specifies the index of the application to retrieve. The value of this parameter must be zero (0) in the first call to the /// function. For each subsequent call, the index must be incremented by 1. The index should only be incremented if the previous /// call to the function returns ERROR_SUCCESS. /// /// /// A string value that receives the product code for the application. The length of the buffer at this location should be large /// enough to hold a null-terminated string value containing the product code. The first 38 TCHAR characters receives the /// GUID for the component, and the 39th character receives a terminating NULL character. /// /// /// A flag that gives the installation context of the application. /// This can be a combination of the following values. /// /// /// Context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED 1 /// The application is installed in the per–user–managed installation context. /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED 2 /// The application is installed in the per–user–unmanaged installation context. /// /// /// MSIINSTALLCONTEXT_MACHINE 4 /// The application is in the per-machine installation installation context. /// /// /// /// /// /// Receives the security identifier (SID) that identifies the user that installed the application. The location receives an empty /// string value if this instance of the application exists in a per-machine installation context. /// /// /// The length of the buffer should be large enough to hold a null-terminated string value containing the SID. If the buffer is too /// small, the function returns ERROR_MORE_DATA and the location pointed to by pcchSid receives the number of TCHAR in /// the SID, not including the terminating NULL character. /// /// /// If szSid is set to NULL and pcchSid is a valid pointer to a location in memory, the function returns ERROR_SUCCESS /// and the location receives the number of TCHAR in the SID, not including the terminating null character. The function can /// then be called again to retrieve the value, with the szSid buffer resized large enough to contain *pcchSid + 1 characters. /// /// /// /// SID type /// Meaning /// /// /// Empty string /// The application is installed in a per-machine installation context. /// /// /// User SID /// The SID for the user that installed the product. /// /// /// /// /// /// Pointer to a location in memory that contains a variable that specifies the number of TCHAR in the SID, not including the /// terminating null character. When the function returns, this variable is set to the size of the requested SID whether or not the /// function can successfully copy the SID and terminating null character into the buffer location pointed to by szSid. The size is /// returned as the number of TCHAR in the requested value, not including the terminating null character. /// /// /// This parameter can be set to NULL only if szSid is also NULL, otherwise the function returns /// ERROR_INVALID_PARAMETER. If szSid and pcchSid are both set to NULL, the function returns ERROR_SUCCESS if /// the SID exists, without retrieving the SID value. /// /// /// /// The MsiEnumClientsEx function returns one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// /// Administrtator privileges are required to enumerate components of applications installed by users other than the current user. /// /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter is passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no more applications to enumerate. /// /// /// ERROR_SUCCESS /// The function succeeded. /// /// /// ERROR_MORE_DATA /// The provided buffer was too small to hold the entire value. /// /// /// ERROR_FUNCTION_FAILED /// The function failed. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumclientsexa UINT MsiEnumClientsExA( LPCSTR szComponent, // LPCSTR szUserSid, DWORD dwContext, DWORD dwProductIndex, CHAR [39] szProductBuf, MSIINSTALLCONTEXT *pdwInstalledContext, LPSTR // szSid, LPDWORD pcchSid ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumClientsExA")] public static extern Win32Error MsiEnumClientsEx([MarshalAs(UnmanagedType.LPTStr)] string szComponent, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szUserSid, MSIINSTALLCONTEXT dwContext, uint dwProductIndex, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szProductBuf, out MSIINSTALLCONTEXT pdwInstalledContext, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szSid, ref uint pcchSid); /// /// /// The MsiEnumClientsEx function enumerates the installed applications that use a specified component. The function /// retrieves a product code for an application each time it is called. /// /// Windows Installer 4.5 or earlier: Not supported. This function is available beginning with Windows Installer 5.0. /// /// /// The component code GUID that identifies the component. The function enumerates the applications that use this component. /// /// /// /// A null-terminated string value that contains a security identifier (SID.) The enumeration of applications extends to users /// identified by this SID. The special SID string s-1-1-0 (Everyone) enumerates all applications for all users in the system. A SID /// value other than s-1-1-0 specifies a user SID for a particular user and enumerates the instances of applications installed by /// the specified user. /// /// /// /// SID type /// Meaning /// /// /// NULL /// Specifies the currently logged-on user. /// /// /// User SID /// Specifies an enumeration for a particular user. An example of an user SID is "S-1-3-64-2415071341-1358098788-3127455600-2561". /// /// /// s-1-1-0 /// Specifies an enumeration for all users in the system. /// /// /// /// Note The special SID string s-1-5-18 (System) cannot be used to enumerate applications that exist in the per-machine /// installation context. Setting the SID value to s-1-5-18 returns ERROR_INVALID_PARAMETER. When dwContext is set to /// MSIINSTALLCONTEXT_MACHINE only, the value of szUserSid must be NULL. /// /// /// /// /// A flag that extends the enumeration to instances of applications installed in the specified installation context. The /// enumeration includes only instances of applications that are installed by the users identified by szUserSid. /// /// This can be a combination of the following values. /// /// /// Context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED 1 /// Include applications installed in the per–user–managed installation context. /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED 2 /// Include applications installed in the per–user–unmanaged installation context. /// /// /// MSIINSTALLCONTEXT_MACHINE 4 /// /// Include applications installed in the per-machine installation context. When dwInstallContext is set to /// MSIINSTALLCONTEXT_MACHINE only, the value of the szUserSID parameter must be NULL. /// /// /// /// /// /// Specifies the index of the application to retrieve. The value of this parameter must be zero (0) in the first call to the /// function. For each subsequent call, the index must be incremented by 1. The index should only be incremented if the previous /// call to the function returns ERROR_SUCCESS. /// /// /// A string value that receives the product code for the application. The length of the buffer at this location should be large /// enough to hold a null-terminated string value containing the product code. The first 38 TCHAR characters receives the /// GUID for the component, and the 39th character receives a terminating NULL character. /// /// /// A flag that gives the installation context of the application. /// This can be a combination of the following values. /// /// /// Context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED 1 /// The application is installed in the per–user–managed installation context. /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED 2 /// The application is installed in the per–user–unmanaged installation context. /// /// /// MSIINSTALLCONTEXT_MACHINE 4 /// The application is in the per-machine installation installation context. /// /// /// /// /// /// Receives the security identifier (SID) that identifies the user that installed the application. The location receives an empty /// string value if this instance of the application exists in a per-machine installation context. /// /// /// The length of the buffer should be large enough to hold a null-terminated string value containing the SID. If the buffer is too /// small, the function returns ERROR_MORE_DATA and the location pointed to by pcchSid receives the number of TCHAR in /// the SID, not including the terminating NULL character. /// /// /// If szSid is set to NULL and pcchSid is a valid pointer to a location in memory, the function returns ERROR_SUCCESS /// and the location receives the number of TCHAR in the SID, not including the terminating null character. The function can /// then be called again to retrieve the value, with the szSid buffer resized large enough to contain *pcchSid + 1 characters. /// /// /// /// SID type /// Meaning /// /// /// Empty string /// The application is installed in a per-machine installation context. /// /// /// User SID /// The SID for the user that installed the product. /// /// /// /// /// /// Pointer to a location in memory that contains a variable that specifies the number of TCHAR in the SID, not including the /// terminating null character. When the function returns, this variable is set to the size of the requested SID whether or not the /// function can successfully copy the SID and terminating null character into the buffer location pointed to by szSid. The size is /// returned as the number of TCHAR in the requested value, not including the terminating null character. /// /// /// This parameter can be set to NULL only if szSid is also NULL, otherwise the function returns /// ERROR_INVALID_PARAMETER. If szSid and pcchSid are both set to NULL, the function returns ERROR_SUCCESS if /// the SID exists, without retrieving the SID value. /// /// /// /// The MsiEnumClientsEx function returns one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// /// Administrtator privileges are required to enumerate components of applications installed by users other than the current user. /// /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter is passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no more applications to enumerate. /// /// /// ERROR_SUCCESS /// The function succeeded. /// /// /// ERROR_MORE_DATA /// The provided buffer was too small to hold the entire value. /// /// /// ERROR_FUNCTION_FAILED /// The function failed. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumclientsexa UINT MsiEnumClientsExA( LPCSTR szComponent, // LPCSTR szUserSid, DWORD dwContext, DWORD dwProductIndex, CHAR [39] szProductBuf, MSIINSTALLCONTEXT *pdwInstalledContext, LPSTR // szSid, LPDWORD pcchSid ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumClientsExA")] public static extern Win32Error MsiEnumClientsEx([MarshalAs(UnmanagedType.LPTStr)] string szComponent, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szUserSid, MSIINSTALLCONTEXT dwContext, uint dwProductIndex, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szProductBuf, [Out, Optional] IntPtr pdwInstalledContext, [Out, Optional] IntPtr szSid, [Out, Optional] IntPtr pcchSid); /// /// /// The MsiEnumClientsEx function enumerates the installed applications that use a specified component and retrieves a /// product code for an application. /// /// Windows Installer 4.5 or earlier: Not supported. This function is available beginning with Windows Installer 5.0. /// /// /// The component code GUID that identifies the component. The function enumerates the applications that use this component. /// /// /// /// A null-terminated string value that contains a security identifier (SID.) The enumeration of applications extends to users /// identified by this SID. The special SID string s-1-1-0 (Everyone) enumerates all applications for all users in the system. A SID /// value other than s-1-1-0 specifies a user SID for a particular user and enumerates the instances of applications installed by /// the specified user. /// /// /// /// SID type /// Meaning /// /// /// NULL /// Specifies the currently logged-on user. /// /// /// User SID /// Specifies an enumeration for a particular user. An example of an user SID is "S-1-3-64-2415071341-1358098788-3127455600-2561". /// /// /// s-1-1-0 /// Specifies an enumeration for all users in the system. /// /// /// /// Note The special SID string s-1-5-18 (System) cannot be used to enumerate applications that exist in the per-machine /// installation context. Setting the SID value to s-1-5-18 returns ERROR_INVALID_PARAMETER. When dwContext is set to /// MSIINSTALLCONTEXT_MACHINE only, the value of szUserSid must be NULL. /// /// /// /// /// A flag that extends the enumeration to instances of applications installed in the specified installation context. The /// enumeration includes only instances of applications that are installed by the users identified by szUserSid. /// /// This can be a combination of the following values. /// /// /// Context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED 1 /// Include applications installed in the per–user–managed installation context. /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED 2 /// Include applications installed in the per–user–unmanaged installation context. /// /// /// MSIINSTALLCONTEXT_MACHINE 4 /// /// Include applications installed in the per-machine installation context. When dwInstallContext is set to /// MSIINSTALLCONTEXT_MACHINE only, the value of the szUserSID parameter must be NULL. /// /// /// /// /// /// A sequence of tuples for each application containing these items: /// product - A string value that receives the product code for the application. /// context - A flag that gives the installation context of the application. /// This can be a combination of the following values. /// /// /// Context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED 1 /// The application is installed in the per–user–managed installation context. /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED 2 /// The application is installed in the per–user–unmanaged installation context. /// /// /// MSIINSTALLCONTEXT_MACHINE 4 /// The application is in the per-machine installation installation context. /// /// /// /// sid - The security identifier (SID) that identifies the user that installed the application. The string value /// is null if this instance of the application exists in a per-machine installation context. /// /// [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumClientsExA")] public static IEnumerable<(string product, MSIINSTALLCONTEXT context, string sid)> MsiEnumClientsEx(string szComponent, [Optional] string szUserSid, MSIINSTALLCONTEXT dwContext) { StringBuilder prodCode = new StringBuilder(MAX_GUID_CHARS + 1); StringBuilder sid = new StringBuilder(1024); for (uint i = 0; true; i++) { prodCode.Length = 0; sid.Length = 0; var sidSz = (uint)sid.Capacity; var err = MsiEnumClientsEx(szComponent, szUserSid, dwContext, i, prodCode, out var ctx, sid, ref sidSz); if (err == Win32Error.ERROR_MORE_DATA) { sid.Capacity = (int)sidSz; err = MsiEnumClientsEx(szComponent, szUserSid, dwContext, i, prodCode, out ctx, sid, ref sidSz); } if (err == Win32Error.ERROR_NO_MORE_ITEMS) yield break; err.ThrowIfFailed(); yield return (prodCode.ToString(), ctx, sidSz == 0 ? null : sid.ToString()); } } /// /// The MsiEnumComponentQualifiers function enumerates the advertised qualifiers for the given component. This function /// retrieves one qualifier each time it is called. /// /// Specifies component whose qualifiers are to be enumerated. /// /// Specifies the index of the qualifier to retrieve. This parameter should be zero for the first call to the /// MsiEnumComponentQualifiers function and then incremented for subsequent calls. Because qualifiers are not ordered, any /// new qualifier has an arbitrary index. This means that the function can return qualifiers in any order. /// /// Pointer to a buffer that receives the qualifier code. /// /// Pointer to a variable that specifies the size, in characters, of the buffer pointed to by the lpQualifierBuf parameter. On /// input, this size should include the terminating null character. On return, the value does not include the null character. /// /// /// Pointer to a buffer that receives the application registered data for the qualifier. This parameter can be null. /// /// /// Pointer to a variable that specifies the size, in characters, of the buffer pointed to by the lpApplicationDataBuf parameter. On /// input, this size should include the terminating null character. On return, the value does not include the null character. This /// parameter can be null only if the lpApplicationDataBuf parameter is null. /// /// /// /// /// Value /// Meaning /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter was passed to the function. /// /// /// ERROR_MORE_DATA /// A buffer is to small to hold the requested data. /// /// /// ERROR_NO_MORE_ITEMS /// There are no qualifiers to return. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// The system does not have enough memory to complete the operation. Available with Windows Server 2003. /// /// /// ERROR_SUCCESS /// A value was enumerated. /// /// /// ERROR_UNKNOWN_COMPONENT /// The specified component is unknown. /// /// /// /// /// /// To enumerate qualifiers, an application should initially call the MsiEnumComponentQualifiers function with the iIndex /// parameter set to zero. The application should then increment the iIndex parameter and call MsiEnumComponentQualifiers /// until there are no more qualifiers (that is, until the function returns ERROR_NO_MORE_ITEMS). /// /// /// When MsiEnumComponentQualifiers returns, the pcchQualifierBuf parameter contains the length of the qualifier string /// stored in the buffer. The count returned does not include the terminating null character. If the buffer is not big enough, /// MsiEnumComponentQualifiers returns ERROR_MORE_DATA, and this parameter contains the size of the string, in characters, /// without counting the null character. The same mechanism applies to pcchDescriptionBuf. /// /// /// When making multiple calls to MsiEnumComponentQualifiers to enumerate all of the component's advertised qualifiers, each /// call should be made from the same thread. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumcomponentqualifiersa UINT MsiEnumComponentQualifiersA( // LPCSTR szComponent, DWORD iIndex, LPSTR lpQualifierBuf, LPDWORD pcchQualifierBuf, LPSTR lpApplicationDataBuf, LPDWORD // pcchApplicationDataBuf ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumComponentQualifiersA")] public static extern Win32Error MsiEnumComponentQualifiers([MarshalAs(UnmanagedType.LPTStr)] string szComponent, uint iIndex, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpQualifierBuf, ref uint pcchQualifierBuf, [Out, Optional] IntPtr lpApplicationDataBuf, [Out, Optional] IntPtr pcchApplicationDataBuf); /// /// The MsiEnumComponents function enumerates the installed components for all products. This function retrieves one /// component code each time it is called. /// /// /// Specifies the index of the component to retrieve. This parameter should be zero for the first call to the /// MsiEnumComponents function and then incremented for subsequent calls. Because components are not ordered, any new /// component has an arbitrary index. This means that the function can return components in any order. /// /// /// Pointer to a buffer that receives the component code. This buffer must be 39 characters long. The first 38 characters are for /// the GUID, and the last character is for the terminating null character. /// /// /// /// /// Value /// Meaning /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter was passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no components to return. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// The system does not have enough memory to complete the operation. Available with Windows Server 2003. /// /// /// ERROR_SUCCESS /// A value was enumerated. /// /// /// /// /// /// To enumerate components, an application should initially call the MsiEnumComponents function with the iComponentIndex /// parameter set to zero. The application should then increment the iComponentIndex parameter and call MsiEnumComponents /// until there are no more components (that is, until the function returns ERROR_NO_MORE_ITEMS). /// /// /// When making multiple calls to MsiEnumComponents to enumerate all of the product's components, each call should be made /// from the same thread. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumcomponentsa UINT MsiEnumComponentsA( DWORD iComponentIndex, // LPSTR lpComponentBuf ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumComponentsA")] public static extern Win32Error MsiEnumComponents(uint iComponentIndex, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpComponentBuf); /// /// /// The MsiEnumComponentsEx function enumerates installed components. The function retrieves the component code for one /// component each time it is called. The component code is the string GUID unique to the component, version, and language. /// /// Windows Installer 4.5 or earlier: Not supported. This function is available beginning with Windows Installer 5.0. /// /// /// /// A null-terminated string that contains a security identifier (SID.) The enumeration of installed components extends to users /// identified by this SID. The special SID string s-1-1-0 (Everyone) specifies an enumeration of all installed components across /// all products of all users in the system. A SID value other than s-1-1-0 specifies a user SID for a particular user and restricts /// the enumeration to instances of applications installed by the specified user. /// /// /// /// SID type /// Meaning /// /// /// NULL /// Specifies the currently logged-on user. /// /// /// User SID /// An enumeration for a specific user in the system. An example of an user SID is "S-1-3-64-2415071341-1358098788-3127455600-2561". /// /// /// s-1-1-0 /// Specifies all users in the system. /// /// /// /// Note The special SID string s-1-5-18 (System) cannot be used to enumerate applications installed in the per-machine /// installation context. Setting the SID value to s-1-5-18 returns ERROR_INVALID_PARAMETER. When dwContext is set to /// MSIINSTALLCONTEXT_MACHINE only, szUserSid must be NULL. /// /// /// /// /// A flag that restricts the enumeration of installed component to instances of products installed in the specified installation /// context. The enumeration includes only product instances installed by the users specified by szUserSid. /// /// /// /// Flag /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED 1 /// Include products that exist in the per–user–managed installation context. /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED 2 /// Include products that exist in the per–user–unmanaged installation context. /// /// /// MSIINSTALLCONTEXT_MACHINE 4 /// /// Include products that exist in the per-machine installation context. When dwInstallContext is set to MSIINSTALLCONTEXT_MACHINE /// only, the szUserSID parameter must be NULL. /// /// /// /// /// /// Specifies the index of the component to retrieve. This parameter must be zero (0) for the first call to /// MsiEnumComponentsEx function. For each subsequent call, the index must be incremented by 1. The index should only be /// incremented if the previous call to the function returns ERROR_SUCCESS. Components are not ordered and can be returned by the /// function in any order. /// /// /// An output buffer that receives the component code GUID for the installed component. The length of the buffer should be large /// enough to hold a null-terminated string value containing the component code. The first 38 TCHAR characters receives the /// GUID for the component, and the 39th character receives a terminating NULL character. /// /// /// A flag that gives the installation context the application that installed the component. /// /// /// Flag /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED 1 /// The application is installed in the per–user–managed installation context. /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED 2 /// The application is installed in the per–user–unmanaged installation context. /// /// /// MSIINSTALLCONTEXT_MACHINE 4 /// The application is installed in the per-machine installation installation context. /// /// /// /// /// /// Receives the security identifier (SID) that identifies the user that installed the application that owns the component. The /// location receives an empty string if this instance of the application is installed in a per-machine installation context. /// /// /// The length of the buffer at this location should be large enough to hold a null-terminated string value containing the SID. If /// the buffer is too small, the function returns ERROR_MORE_DATA and the location pointed to by pcchSid receives the number /// of TCHAR in the SID, not including the terminating NULL character. /// /// /// If szSid is set to NULL and pcchSid is a valid pointer to a location in memory, the function returns ERROR_SUCCESS /// and the location receives the number of TCHAR in the SID, not including the terminating null character. The function can /// then be called again to retrieve the value, with the szSid buffer resized large enough to contain *pcchSid + 1 characters. /// /// /// /// SID type /// Meaning /// /// /// Empty string /// The application is installed in a per-machine installation context. /// /// /// User SID /// The SID for the user in the system that installed the application. /// /// /// /// /// /// Receives the number of TCHAR in the SID, not including the terminating null character. When the function returns, this /// variable is set to the size of the requested SID whether or not the function can successfully copy the SID and terminating null /// character into the buffer location pointed to by szSid. The size is returned as the number of TCHAR in the requested /// value, not including the terminating null character. /// /// /// This parameter can be set to NULL only if szSid is also NULL, otherwise the function returns /// ERROR_INVALID_PARAMETER. If szSid and pcchSid are both set to NULL, the function returns ERROR_SUCCESS if /// the SID exists, without retrieving the SID value. /// /// /// /// The MsiEnumProductsEx function returns one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// /// Administrator privileges are required to enumerate components of applications installed by users other than the current user. /// /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter is passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no more components to enumerate. /// /// /// ERROR_SUCCESS /// The function succeeded. /// /// /// ERROR_MORE_DATA /// The provided buffer was too small to hold the entire value. /// /// /// ERROR_FUNCTION_FAILED /// The function failed. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumcomponentsexa UINT MsiEnumComponentsExA( LPCSTR szUserSid, // DWORD dwContext, DWORD dwIndex, CHAR [39] szInstalledComponentCode, MSIINSTALLCONTEXT *pdwInstalledContext, LPSTR szSid, LPDWORD // pcchSid ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumComponentsExA")] public static extern Win32Error MsiEnumComponentsEx([Optional, MarshalAs(UnmanagedType.LPTStr)] string szUserSid, MSIINSTALLCONTEXT dwContext, uint dwIndex, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szInstalledComponentCode, out MSIINSTALLCONTEXT pdwInstalledContext, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szSid, ref uint pcchSid); /// /// /// The MsiEnumComponentsEx function enumerates installed components. The function retrieves the component code for one /// component each time it is called. The component code is the string GUID unique to the component, version, and language. /// /// Windows Installer 4.5 or earlier: Not supported. This function is available beginning with Windows Installer 5.0. /// /// /// /// A null-terminated string that contains a security identifier (SID.) The enumeration of installed components extends to users /// identified by this SID. The special SID string s-1-1-0 (Everyone) specifies an enumeration of all installed components across /// all products of all users in the system. A SID value other than s-1-1-0 specifies a user SID for a particular user and restricts /// the enumeration to instances of applications installed by the specified user. /// /// /// /// SID type /// Meaning /// /// /// NULL /// Specifies the currently logged-on user. /// /// /// User SID /// An enumeration for a specific user in the system. An example of an user SID is "S-1-3-64-2415071341-1358098788-3127455600-2561". /// /// /// s-1-1-0 /// Specifies all users in the system. /// /// /// /// Note The special SID string s-1-5-18 (System) cannot be used to enumerate applications installed in the per-machine /// installation context. Setting the SID value to s-1-5-18 returns ERROR_INVALID_PARAMETER. When dwContext is set to /// MSIINSTALLCONTEXT_MACHINE only, szUserSid must be NULL. /// /// /// /// /// A flag that restricts the enumeration of installed component to instances of products installed in the specified installation /// context. The enumeration includes only product instances installed by the users specified by szUserSid. /// /// /// /// Flag /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED 1 /// Include products that exist in the per–user–managed installation context. /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED 2 /// Include products that exist in the per–user–unmanaged installation context. /// /// /// MSIINSTALLCONTEXT_MACHINE 4 /// /// Include products that exist in the per-machine installation context. When dwInstallContext is set to MSIINSTALLCONTEXT_MACHINE /// only, the szUserSID parameter must be NULL. /// /// /// /// /// /// Specifies the index of the component to retrieve. This parameter must be zero (0) for the first call to /// MsiEnumComponentsEx function. For each subsequent call, the index must be incremented by 1. The index should only be /// incremented if the previous call to the function returns ERROR_SUCCESS. Components are not ordered and can be returned by the /// function in any order. /// /// /// An output buffer that receives the component code GUID for the installed component. The length of the buffer should be large /// enough to hold a null-terminated string value containing the component code. The first 38 TCHAR characters receives the /// GUID for the component, and the 39th character receives a terminating NULL character. /// /// /// A flag that gives the installation context the application that installed the component. /// /// /// Flag /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED 1 /// The application is installed in the per–user–managed installation context. /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED 2 /// The application is installed in the per–user–unmanaged installation context. /// /// /// MSIINSTALLCONTEXT_MACHINE 4 /// The application is installed in the per-machine installation installation context. /// /// /// /// /// /// Receives the security identifier (SID) that identifies the user that installed the application that owns the component. The /// location receives an empty string if this instance of the application is installed in a per-machine installation context. /// /// /// The length of the buffer at this location should be large enough to hold a null-terminated string value containing the SID. If /// the buffer is too small, the function returns ERROR_MORE_DATA and the location pointed to by pcchSid receives the number /// of TCHAR in the SID, not including the terminating NULL character. /// /// /// If szSid is set to NULL and pcchSid is a valid pointer to a location in memory, the function returns ERROR_SUCCESS /// and the location receives the number of TCHAR in the SID, not including the terminating null character. The function can /// then be called again to retrieve the value, with the szSid buffer resized large enough to contain *pcchSid + 1 characters. /// /// /// /// SID type /// Meaning /// /// /// Empty string /// The application is installed in a per-machine installation context. /// /// /// User SID /// The SID for the user in the system that installed the application. /// /// /// /// /// /// Receives the number of TCHAR in the SID, not including the terminating null character. When the function returns, this /// variable is set to the size of the requested SID whether or not the function can successfully copy the SID and terminating null /// character into the buffer location pointed to by szSid. The size is returned as the number of TCHAR in the requested /// value, not including the terminating null character. /// /// /// This parameter can be set to NULL only if szSid is also NULL, otherwise the function returns /// ERROR_INVALID_PARAMETER. If szSid and pcchSid are both set to NULL, the function returns ERROR_SUCCESS if /// the SID exists, without retrieving the SID value. /// /// /// /// The MsiEnumProductsEx function returns one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// /// Administrator privileges are required to enumerate components of applications installed by users other than the current user. /// /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter is passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no more components to enumerate. /// /// /// ERROR_SUCCESS /// The function succeeded. /// /// /// ERROR_MORE_DATA /// The provided buffer was too small to hold the entire value. /// /// /// ERROR_FUNCTION_FAILED /// The function failed. /// /// /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumcomponentsexa UINT MsiEnumComponentsExA( LPCSTR szUserSid, // DWORD dwContext, DWORD dwIndex, CHAR [39] szInstalledComponentCode, MSIINSTALLCONTEXT *pdwInstalledContext, LPSTR szSid, LPDWORD // pcchSid ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumComponentsExA")] public static extern Win32Error MsiEnumComponentsEx([Optional, MarshalAs(UnmanagedType.LPTStr)] string szUserSid, MSIINSTALLCONTEXT dwContext, uint dwIndex, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szInstalledComponentCode, [Out, Optional] IntPtr pdwInstalledContext, [Out, Optional] IntPtr szSid, [Out, Optional] IntPtr pcchSid); /// /// The MsiEnumFeatures function enumerates the published features for a given product. This function retrieves one feature /// ID each time it is called. /// /// Null-terminated string specifying the product code of the product whose features are to be enumerated. /// /// Specifies the index of the feature to retrieve. This parameter should be zero for the first call to the MsiEnumFeatures /// function and then incremented for subsequent calls. Because features are not ordered, any new feature has an arbitrary index. /// This means that the function can return features in any order. /// /// /// Pointer to a buffer that receives the feature ID. The size of the buffer must hold a string value of length MAX_FEATURE_CHARS+1. /// The function returns ERROR_MORE_DATA if the length of the feature ID exceeds MAX_FEATURE_CHARS. /// /// /// Pointer to a buffer that receives the feature ID of the parent of the feature. The size of the buffer must hold a string value /// of length MAX_FEATURE_CHARS+1. If the length of the feature ID of the parent feature exceeds MAX_FEATURE_CHARS, only the /// first MAX_FEATURE_CHARS characters get copied into the buffer. /// /// /// /// /// Value /// Meaning /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter was passed to the function. /// /// /// ERROR_MORE_DATA /// A buffer is too small to hold the requested data. /// /// /// ERROR_NO_MORE_ITEMS /// There are no features to return. /// /// /// ERROR_SUCCESS /// A value was enumerated. /// /// /// ERROR_UNKNOWN_PRODUCT /// The specified product is unknown. /// /// /// /// /// To enumerate features, an application should initially call the MsiEnumFeatures function with the iFeatureIndex parameter /// set to zero. The application should then increment the iFeatureIndex parameter and call MsiEnumFeatures until there are /// no more features (that is, until the function returns ERROR_NO_MORE_ITEMS). /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumfeaturesa UINT MsiEnumFeaturesA( LPCSTR szProduct, DWORD // iFeatureIndex, LPSTR lpFeatureBuf, LPSTR lpParentBuf ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumFeaturesA")] public static extern Win32Error MsiEnumFeatures([MarshalAs(UnmanagedType.LPTStr)] string szProduct, uint iFeatureIndex, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpFeatureBuf, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpParentBuf); /// /// /// The MsiEnumPatches function enumerates all of the patches that have been applied to a product. The function returns the /// patch code GUID for each patch that has been applied to the product and returns a list of transforms from each patch that apply /// to the product. Note that patches may have many transforms only some of which are applicable to a particular product. The list /// of transforms are returned in the same format as the value of the TRANSFORMS property. /// /// /// Note pcchTransformsBuf is not set to the number of characters copied to lpTransformsBuf upon a successful return of MsiEnumPatches. /// /// /// Specifies the product code of the product for which patches are to be enumerated. /// /// Specifies the index of the patch to retrieve. This parameter should be zero for the first call to the MsiEnumPatches /// function and then incremented for subsequent calls. /// /// Pointer to a buffer that receives the patch's GUID. This argument is required. /// /// Pointer to a buffer that receives the list of transforms in the patch that are applicable to the product. This argument is /// required and cannot be Null. /// /// /// Set to the number of characters copied to lpTransformsBuf upon an unsuccessful return of the function. Not set for a successful /// return. On input, this is the full size of the buffer, including a space for a terminating null character. If the buffer passed /// in is too small, the count returned does not include the terminating null character. /// /// /// /// /// Value /// Meaning /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter was passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no patches to return. /// /// /// ERROR_SUCCESS /// A value was enumerated. /// /// /// ERROR_MORE_DATA /// A buffer is too small to hold the requested data. /// /// /// /// /// /// To enumerate patches, an application should initially call the MsiEnumPatches function with the iPatchIndex parameter set /// to zero. The application should then increment the iPatchIndex parameter and call MsiEnumPatches until there are no more /// products (until the function returns ERROR_NO_MORE_ITEMS). /// /// /// If the buffer is too small to hold the requested data, MsiEnumPatches returns ERROR_MORE_DATA and pcchTransformsBuf /// contains the number of characters copied to lpTransformsBuf, without counting the Null character. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumpatchesa UINT MsiEnumPatchesA( LPCSTR szProduct, DWORD // iPatchIndex, LPSTR lpPatchBuf, LPSTR lpTransformsBuf, LPDWORD pcchTransformsBuf ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumPatchesA")] public static extern Win32Error MsiEnumPatches([MarshalAs(UnmanagedType.LPTStr)] string szProduct, uint iPatchIndex, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpPatchBuf, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpTransformsBuf, ref uint pcchTransformsBuf); /// /// The MsiEnumPatchesEx function enumerates all patches in a specific context or across all contexts. Patches already /// applied to products are enumerated. Patches that have been registered but not yet applied to products are also enumerated. /// /// /// A null-terminated string that specifies the ProductCode GUID of the product whose patches are enumerated. If non- NULL, /// patch enumeration is restricted to instances of this product under the user and context specified by szUserSid and dwContext. If /// NULL, the patches for all products under the specified context are enumerated. /// /// /// /// A null-terminated string that specifies a security identifier (SID) that restricts the context of enumeration. The special SID /// string "S-1-1-0" (Everyone) specifies enumeration across all users in the system. A SID value other than "S-1-1-0" is considered /// a user SID and restricts enumeration to that user. When enumerating for a user other than current user, any patches that were /// applied in a per-user-unmanaged context using a version less than Windows Installer version 3.0, are not enumerated. This /// parameter can be set to NULL to specify the current user. /// /// /// /// SID type /// Meaning /// /// /// NULL /// Specifies the currently logged-on user. /// /// /// User SID /// An enumeration for a specific user in the system. An example of user SID is "S-1-3-64-2415071341-1358098788-3127455600-2561". /// /// /// s-1-1-0 /// An enumeration across all users in the system. /// /// /// /// Note The special SID string "S-1-5-18" (System) cannot be used to enumerate products or patches installed as per-machine. /// Setting the SID value to "S-1-5-18" returns ERROR_INVALID_PARAMETER. When dwContext is set to /// MSIINSTALLCONTEXT_MACHINE only, szUserSid must be NULL. /// /// /// /// /// Restricts the enumeration to one or a combination of contexts. This parameter can be any one or a combination of the following values. /// /// /// /// Context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED /// /// The enumeration that is extended to all per-user-managed installations for the users that szUserSid specifies. An invalid SID /// returns no items. /// /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED /// /// In this context, only patches installed with Windows Installer version 3.0 are enumerated for users that are not the current /// user. For the current user, the function enumerates all installed and new patches. An invalid SID for szUserSid returns no items. /// /// /// /// MSIINSTALLCONTEXT_MACHINE /// /// An enumeration that is extended to all per-machine installations. When dwContext is set to MSIINSTALLCONTEXT_MACHINE only, the /// szUserSid parameter must be NULL. /// /// /// /// /// /// The filter for enumeration. This parameter can be one or a combination of the following parameters. /// /// /// Filter /// Meaning /// /// /// MSIPATCHSTATE_APPLIED 1 /// The enumeration includes patches that have been applied. Enumeration does not include superseded or obsolete patches. /// /// /// MSIPATCHSTATE_SUPERSEDED 2 /// The enumeration includes patches that are marked as superseded. /// /// /// MSIPATCHSTATE_OBSOLETED 4 /// The enumeration includes patches that are marked as obsolete. /// /// /// MSIPATCHSTATE_REGISTERED 8 /// /// The enumeration includes patches that are registered but not yet applied. The MsiSourceListAddSourceEx function can register new patches. /// /// /// /// MSIPATCHSTATE_ALL 15 /// The enumeration includes all applied, obsolete, superseded, and registered patches. /// /// /// /// /// The index of the patch to retrieve. This parameter must be zero for the first call to the MsiEnumPatchesEx function and /// then incremented for subsequent calls. The dwIndex parameter should be incremented only if the previous call returned ERROR_SUCCESS. /// /// /// An output buffer to contain the GUID of the patch being enumerated. The buffer should be large enough to hold the GUID. This /// parameter can be NULL. /// /// /// An output buffer to contain the ProductCode GUID of the product that receives this patch. The buffer should be large enough to /// hold the GUID. This parameter can be NULL. /// /// /// Returns the context of the patch being enumerated. The output value can be MSIINSTALLCONTEXT_USERMANAGED, /// MSIINSTALLCONTEXT_USERUNMANAGED, or MSIINSTALLCONTEXT_MACHINE. This parameter can be NULL. /// /// /// /// An output buffer that receives the string SID of the account under which this patch instance exists. This buffer returns an /// empty string for a per-machine context. /// /// /// This buffer should be large enough to contain the SID. If the buffer is too small, the function returns ERROR_MORE_DATA /// and sets *pcchTargetUserSid to the number of TCHAR in the value, not including the terminating NULL character. /// /// /// If the szTargetUserSid is set to NULL and pcchTargetUserSid is set to a valid pointer, the function returns /// ERROR_SUCCESS and sets *pcchTargetUserSid to the number of TCHAR in the value, not including the terminating /// NULL character. The function can then be called again to retrieve the value, with szTargetUserSid buffer large enough to /// contain *pcchTargetUserSid + 1 characters. /// /// /// If szTargetUserSid and pcchTargetUserSid are both set to NULL, the function returns ERROR_SUCCESS if the value /// exists, without retrieving the value. /// /// /// /// /// A pointer to a variable that specifies the number of TCHAR in the szTargetUserSid buffer. When the function returns, this /// parameter is set to the size of the requested value whether or not the function copies the value into the specified buffer. The /// size is returned as the number of TCHAR in the requested value, not including the terminating null character. /// /// This parameter can be set to NULL only if szTargetUserSid is also NULL, otherwise the function returns ERROR_INVALID_PARAMETER. /// /// /// The MsiEnumPatchesEx function returns one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// The function fails trying to access a resource with insufficient privileges. /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter is passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no more patches to enumerate. /// /// /// ERROR_SUCCESS /// The patch is successfully enumerated. /// /// /// ERROR_UNKNOWN_PRODUCT /// The product that szProduct specifies is not installed on the computer in the specified contexts. /// /// /// ERROR_MORE_DATA /// /// This is returned when pcchTargetUserSid points to a buffer size less than required to copy the SID. In this case, the user can /// fix the buffer and call MsiEnumPatchesEx again for the same index value. /// /// /// /// /// /// Non-administrators can enumerate patches within their visibility only. Administrators can enumerate patches for other user contexts. /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumpatchesexa UINT MsiEnumPatchesExA( LPCSTR szProductCode, // LPCSTR szUserSid, DWORD dwContext, DWORD dwFilter, DWORD dwIndex, CHAR [39] szPatchCode, CHAR [39] szTargetProductCode, // MSIINSTALLCONTEXT *pdwTargetProductContext, LPSTR szTargetUserSid, LPDWORD pcchTargetUserSid ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumPatchesExA")] public static extern Win32Error MsiEnumPatchesEx([MarshalAs(UnmanagedType.LPTStr)] string szProductCode, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szUserSid, MSIINSTALLCONTEXT dwContext, MSIPATCHSTATE dwFilter, uint dwIndex, [Out, Optional, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szPatchCode, [Out, Optional, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szTargetProductCode, out MSIINSTALLCONTEXT pdwTargetProductContext, [Out, Optional, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szTargetUserSid, ref uint pcchTargetUserSid); /// /// The MsiEnumPatchesEx function enumerates all patches in a specific context or across all contexts. Patches already /// applied to products are enumerated. Patches that have been registered but not yet applied to products are also enumerated. /// /// /// A null-terminated string that specifies the ProductCode GUID of the product whose patches are enumerated. If non- NULL, /// patch enumeration is restricted to instances of this product under the user and context specified by szUserSid and dwContext. If /// NULL, the patches for all products under the specified context are enumerated. /// /// /// /// A null-terminated string that specifies a security identifier (SID) that restricts the context of enumeration. The special SID /// string "S-1-1-0" (Everyone) specifies enumeration across all users in the system. A SID value other than "S-1-1-0" is considered /// a user SID and restricts enumeration to that user. When enumerating for a user other than current user, any patches that were /// applied in a per-user-unmanaged context using a version less than Windows Installer version 3.0, are not enumerated. This /// parameter can be set to NULL to specify the current user. /// /// /// /// SID type /// Meaning /// /// /// NULL /// Specifies the currently logged-on user. /// /// /// User SID /// An enumeration for a specific user in the system. An example of user SID is "S-1-3-64-2415071341-1358098788-3127455600-2561". /// /// /// s-1-1-0 /// An enumeration across all users in the system. /// /// /// /// Note The special SID string "S-1-5-18" (System) cannot be used to enumerate products or patches installed as per-machine. /// Setting the SID value to "S-1-5-18" returns ERROR_INVALID_PARAMETER. When dwContext is set to /// MSIINSTALLCONTEXT_MACHINE only, szUserSid must be NULL. /// /// /// /// /// Restricts the enumeration to one or a combination of contexts. This parameter can be any one or a combination of the following values. /// /// /// /// Context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED /// /// The enumeration that is extended to all per-user-managed installations for the users that szUserSid specifies. An invalid SID /// returns no items. /// /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED /// /// In this context, only patches installed with Windows Installer version 3.0 are enumerated for users that are not the current /// user. For the current user, the function enumerates all installed and new patches. An invalid SID for szUserSid returns no items. /// /// /// /// MSIINSTALLCONTEXT_MACHINE /// /// An enumeration that is extended to all per-machine installations. When dwContext is set to MSIINSTALLCONTEXT_MACHINE only, the /// szUserSid parameter must be NULL. /// /// /// /// /// /// The filter for enumeration. This parameter can be one or a combination of the following parameters. /// /// /// Filter /// Meaning /// /// /// MSIPATCHSTATE_APPLIED 1 /// The enumeration includes patches that have been applied. Enumeration does not include superseded or obsolete patches. /// /// /// MSIPATCHSTATE_SUPERSEDED 2 /// The enumeration includes patches that are marked as superseded. /// /// /// MSIPATCHSTATE_OBSOLETED 4 /// The enumeration includes patches that are marked as obsolete. /// /// /// MSIPATCHSTATE_REGISTERED 8 /// /// The enumeration includes patches that are registered but not yet applied. The MsiSourceListAddSourceEx function can register new patches. /// /// /// /// MSIPATCHSTATE_ALL 15 /// The enumeration includes all applied, obsolete, superseded, and registered patches. /// /// /// /// /// The index of the patch to retrieve. This parameter must be zero for the first call to the MsiEnumPatchesEx function and /// then incremented for subsequent calls. The dwIndex parameter should be incremented only if the previous call returned ERROR_SUCCESS. /// /// /// An output buffer to contain the GUID of the patch being enumerated. The buffer should be large enough to hold the GUID. This /// parameter can be NULL. /// /// /// An output buffer to contain the ProductCode GUID of the product that receives this patch. The buffer should be large enough to /// hold the GUID. This parameter can be NULL. /// /// /// Returns the context of the patch being enumerated. The output value can be MSIINSTALLCONTEXT_USERMANAGED, /// MSIINSTALLCONTEXT_USERUNMANAGED, or MSIINSTALLCONTEXT_MACHINE. This parameter can be NULL. /// /// /// /// An output buffer that receives the string SID of the account under which this patch instance exists. This buffer returns an /// empty string for a per-machine context. /// /// /// This buffer should be large enough to contain the SID. If the buffer is too small, the function returns ERROR_MORE_DATA /// and sets *pcchTargetUserSid to the number of TCHAR in the value, not including the terminating NULL character. /// /// /// If the szTargetUserSid is set to NULL and pcchTargetUserSid is set to a valid pointer, the function returns /// ERROR_SUCCESS and sets *pcchTargetUserSid to the number of TCHAR in the value, not including the terminating /// NULL character. The function can then be called again to retrieve the value, with szTargetUserSid buffer large enough to /// contain *pcchTargetUserSid + 1 characters. /// /// /// If szTargetUserSid and pcchTargetUserSid are both set to NULL, the function returns ERROR_SUCCESS if the value /// exists, without retrieving the value. /// /// /// /// /// A pointer to a variable that specifies the number of TCHAR in the szTargetUserSid buffer. When the function returns, this /// parameter is set to the size of the requested value whether or not the function copies the value into the specified buffer. The /// size is returned as the number of TCHAR in the requested value, not including the terminating null character. /// /// This parameter can be set to NULL only if szTargetUserSid is also NULL, otherwise the function returns ERROR_INVALID_PARAMETER. /// /// /// The MsiEnumPatchesEx function returns one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// The function fails trying to access a resource with insufficient privileges. /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter is passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no more patches to enumerate. /// /// /// ERROR_SUCCESS /// The patch is successfully enumerated. /// /// /// ERROR_UNKNOWN_PRODUCT /// The product that szProduct specifies is not installed on the computer in the specified contexts. /// /// /// ERROR_MORE_DATA /// /// This is returned when pcchTargetUserSid points to a buffer size less than required to copy the SID. In this case, the user can /// fix the buffer and call MsiEnumPatchesEx again for the same index value. /// /// /// /// /// /// Non-administrators can enumerate patches within their visibility only. Administrators can enumerate patches for other user contexts. /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumpatchesexa UINT MsiEnumPatchesExA( LPCSTR szProductCode, // LPCSTR szUserSid, DWORD dwContext, DWORD dwFilter, DWORD dwIndex, CHAR [39] szPatchCode, CHAR [39] szTargetProductCode, // MSIINSTALLCONTEXT *pdwTargetProductContext, LPSTR szTargetUserSid, LPDWORD pcchTargetUserSid ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumPatchesExA")] public static extern Win32Error MsiEnumPatchesEx([MarshalAs(UnmanagedType.LPTStr)] string szProductCode, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szUserSid, MSIINSTALLCONTEXT dwContext, MSIPATCHSTATE dwFilter, uint dwIndex, [Out, Optional] IntPtr szPatchCode, [Out, Optional] IntPtr szTargetProductCode, [Out, Optional] IntPtr pdwTargetProductContext, [Out, Optional] IntPtr szTargetUserSid, [Out, Optional] IntPtr pcchTargetUserSid); /// /// The MsiEnumProducts function enumerates through all the products currently advertised or installed. Products that are /// installed in both the per-user and per-machine installation context and advertisements are enumerated. /// /// /// Specifies the index of the product to retrieve. This parameter should be zero for the first call to the MsiEnumProducts /// function and then incremented for subsequent calls. Because products are not ordered, any new product has an arbitrary index. /// This means that the function can return products in any order. /// /// /// Pointer to a buffer that receives the product code. This buffer must be 39 characters long. The first 38 characters are for the /// GUID, and the last character is for the terminating null character. /// /// /// /// /// Value /// Meaning /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter was passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no products to return. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// The system does not have enough memory to complete the operation. Available with Windows Server 2003. /// /// /// ERROR_SUCCESS /// A value was enumerated. /// /// /// /// /// /// To enumerate products, an application should initially call the MsiEnumProducts function with the iProductIndex parameter /// set to zero. The application should then increment the iProductIndex parameter and call MsiEnumProducts until there are /// no more products (until the function returns ERROR_NO_MORE_ITEMS). /// /// /// When making multiple calls to MsiEnumProducts to enumerate all of the products, each call should be made from the same thread. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumproductsa UINT MsiEnumProductsA( DWORD iProductIndex, LPSTR // lpProductBuf ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumProductsA")] public static extern Win32Error MsiEnumProducts(uint iProductIndex, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpProductBuf); /// /// The MsiEnumProductsEx function enumerates through one or all the instances of products that are currently advertised or /// installed in the specified contexts. This function supersedes MsiEnumProducts. /// /// /// ProductCode GUID of the product to be enumerated. Only instances of products within the scope of the context specified by the /// szUserSid and dwContext parameters are enumerated. This parameter can be set to NULL to enumerate all products in the /// specified context. /// /// /// /// Null-terminated string that specifies a security identifier (SID) that restricts the context of enumeration. The special SID /// string s-1-1-0 (Everyone) specifies enumeration across all users in the system. A SID value other than s-1-1-0 is considered a /// user-SID and restricts enumeration to the current user or any user in the system. This parameter can be set to NULL to /// restrict the enumeration scope to the current user. /// /// /// /// SID type /// Meaning /// /// /// NULL /// Specifies the currently logged-on user. /// /// /// User SID /// Specifies enumeration for a particular user in the system. An example of user SID is "S-1-3-64-2415071341-1358098788-3127455600-2561". /// /// /// s-1-1-0 /// Specifies enumeration across all users in the system. /// /// /// /// Note The special SID string s-1-5-18 (System) cannot be used to enumerate products or patches installed as per-machine. /// When dwContext is set to MSIINSTALLCONTEXT_MACHINE only, szUserSid must be NULL. /// /// /// /// /// Restricts the enumeration to a context. This parameter can be any one or a combination of the values shown in the following table. /// /// /// /// Context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED /// /// Enumeration extended to all per–user–managed installations for the users specified by szUserSid. An invalid SID returns no items. /// /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED /// /// Enumeration extended to all per–user–unmanaged installations for the users specified by szUserSid. An invalid SID returns no items. /// /// /// /// MSIINSTALLCONTEXT_MACHINE /// /// Enumeration extended to all per-machine installations. When dwInstallContext is set to MSIINSTALLCONTEXT_MACHINE only, the /// szUserSID parameter must be NULL. /// /// /// /// /// /// Specifies the index of the product to retrieve. This parameter must be zero for the first call to the MsiEnumProductsEx /// function and then incremented for subsequent calls. The index should be incremented, only if the previous call has returned /// ERROR_SUCCESS. Because products are not ordered, any new product has an arbitrary index. This means that the function can return /// products in any order. /// /// /// Null-terminated string of TCHAR that gives the ProductCode GUID of the product instance being enumerated. This parameter /// can be NULL. /// /// /// Returns the context of the product instance being enumerated. The output value can be MSIINSTALLCONTEXT_USERMANAGED, /// MSIINSTALLCONTEXT_USERUNMANAGED, or MSIINSTALLCONTEXT_MACHINE. This parameter can be NULL. /// /// /// /// An output buffer that receives the string SID of the account under which this product instance exists. This buffer returns an /// empty string for an instance installed in a per-machine context. /// /// /// This buffer should be large enough to contain the SID. If the buffer is too small, the function returns ERROR_MORE_DATA and sets /// *pcchSid to the number of TCHAR in the SID, not including the terminating NULL character. /// /// /// If szSid is set to NULL and pcchSid is set to a valid pointer, the function returns ERROR_SUCCESS and sets *pcchSid to /// the number of TCHAR in the value, not including the terminating NULL. The function can then be called again to /// retrieve the value, with the szSid buffer large enough to contain *pcchSid + 1 characters. /// /// /// If szSid and pcchSid are both set to NULL, the function returns ERROR_SUCCESS if the value exists, without retrieving the value. /// /// /// /// /// When calling the function, this parameter should be a pointer to a variable that specifies the number of TCHAR in the /// szSid buffer. When the function returns, this parameter is set to the size of the requested value whether or not the function /// copies the value into the specified buffer. The size is returned as the number of TCHAR in the requested value, not /// including the terminating null character. /// /// This parameter can be set to NULL only if szSid is also NULL, otherwise the function returns ERROR_INVALID_PARAMETER. /// /// /// The MsiEnumProductsEx function returns one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// If the scope includes users other than the current user, you need administrator privileges. /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter was passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no more products to enumerate. /// /// /// ERROR_SUCCESS /// A product is enumerated. /// /// /// ERROR_MORE_DATA /// The szSid parameter is too small to get the user SID. /// /// /// ERROR_UNKNOWN_PRODUCT /// The product is not installed on the computer in the specified context. /// /// /// ERROR_FUNCTION_FAILED /// An unexpected internal failure. /// /// /// /// /// /// To enumerate products, an application must initially call the MsiEnumProductsEx function with the iIndex parameter set to /// zero. The application must then increment the iProductIndex parameter and call MsiEnumProductsEx until it returns /// ERROR_NO_MORE_ITEMS and there are no more products to enumerate. /// /// /// When making multiple calls to MsiEnumProductsEx to enumerate all of the products, each call must be made from the same thread. /// /// /// A user must have administrator privileges to enumerate products across all user accounts or a user account other than the /// current user account. The enumeration skips products that are advertised only (such as products not installed) in the /// per-user-unmanaged context when enumerating across all users or a user other than the current user. /// /// Use MsiGetProductInfoEx to get the state or other information about each product instance enumerated by MsiEnumProductsEx. /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumproductsexa UINT MsiEnumProductsExA( LPCSTR szProductCode, // LPCSTR szUserSid, DWORD dwContext, DWORD dwIndex, CHAR [39] szInstalledProductCode, MSIINSTALLCONTEXT *pdwInstalledContext, LPSTR // szSid, LPDWORD pcchSid ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumProductsExA")] public static extern Win32Error MsiEnumProductsEx([Optional, MarshalAs(UnmanagedType.LPTStr)] string szProductCode, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szUserSid, MSIINSTALLCONTEXT dwContext, uint dwIndex, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szInstalledProductCode, out MSIINSTALLCONTEXT pdwInstalledContext, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szSid, ref uint pcchSid); /// /// The MsiEnumProductsEx function enumerates through one or all the instances of products that are currently advertised or /// installed in the specified contexts. This function supersedes MsiEnumProducts. /// /// /// ProductCode GUID of the product to be enumerated. Only instances of products within the scope of the context specified by the /// szUserSid and dwContext parameters are enumerated. This parameter can be set to NULL to enumerate all products in the /// specified context. /// /// /// /// Null-terminated string that specifies a security identifier (SID) that restricts the context of enumeration. The special SID /// string s-1-1-0 (Everyone) specifies enumeration across all users in the system. A SID value other than s-1-1-0 is considered a /// user-SID and restricts enumeration to the current user or any user in the system. This parameter can be set to NULL to /// restrict the enumeration scope to the current user. /// /// /// /// SID type /// Meaning /// /// /// NULL /// Specifies the currently logged-on user. /// /// /// User SID /// Specifies enumeration for a particular user in the system. An example of user SID is "S-1-3-64-2415071341-1358098788-3127455600-2561". /// /// /// s-1-1-0 /// Specifies enumeration across all users in the system. /// /// /// /// Note The special SID string s-1-5-18 (System) cannot be used to enumerate products or patches installed as per-machine. /// When dwContext is set to MSIINSTALLCONTEXT_MACHINE only, szUserSid must be NULL. /// /// /// /// /// Restricts the enumeration to a context. This parameter can be any one or a combination of the values shown in the following table. /// /// /// /// Context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED /// /// Enumeration extended to all per–user–managed installations for the users specified by szUserSid. An invalid SID returns no items. /// /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED /// /// Enumeration extended to all per–user–unmanaged installations for the users specified by szUserSid. An invalid SID returns no items. /// /// /// /// MSIINSTALLCONTEXT_MACHINE /// /// Enumeration extended to all per-machine installations. When dwInstallContext is set to MSIINSTALLCONTEXT_MACHINE only, the /// szUserSID parameter must be NULL. /// /// /// /// /// /// Specifies the index of the product to retrieve. This parameter must be zero for the first call to the MsiEnumProductsEx /// function and then incremented for subsequent calls. The index should be incremented, only if the previous call has returned /// ERROR_SUCCESS. Because products are not ordered, any new product has an arbitrary index. This means that the function can return /// products in any order. /// /// /// Null-terminated string of TCHAR that gives the ProductCode GUID of the product instance being enumerated. This parameter /// can be NULL. /// /// /// Returns the context of the product instance being enumerated. The output value can be MSIINSTALLCONTEXT_USERMANAGED, /// MSIINSTALLCONTEXT_USERUNMANAGED, or MSIINSTALLCONTEXT_MACHINE. This parameter can be NULL. /// /// /// /// An output buffer that receives the string SID of the account under which this product instance exists. This buffer returns an /// empty string for an instance installed in a per-machine context. /// /// /// This buffer should be large enough to contain the SID. If the buffer is too small, the function returns ERROR_MORE_DATA and sets /// *pcchSid to the number of TCHAR in the SID, not including the terminating NULL character. /// /// /// If szSid is set to NULL and pcchSid is set to a valid pointer, the function returns ERROR_SUCCESS and sets *pcchSid to /// the number of TCHAR in the value, not including the terminating NULL. The function can then be called again to /// retrieve the value, with the szSid buffer large enough to contain *pcchSid + 1 characters. /// /// /// If szSid and pcchSid are both set to NULL, the function returns ERROR_SUCCESS if the value exists, without retrieving the value. /// /// /// /// /// When calling the function, this parameter should be a pointer to a variable that specifies the number of TCHAR in the /// szSid buffer. When the function returns, this parameter is set to the size of the requested value whether or not the function /// copies the value into the specified buffer. The size is returned as the number of TCHAR in the requested value, not /// including the terminating null character. /// /// This parameter can be set to NULL only if szSid is also NULL, otherwise the function returns ERROR_INVALID_PARAMETER. /// /// /// The MsiEnumProductsEx function returns one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_ACCESS_DENIED /// If the scope includes users other than the current user, you need administrator privileges. /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter was passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no more products to enumerate. /// /// /// ERROR_SUCCESS /// A product is enumerated. /// /// /// ERROR_MORE_DATA /// The szSid parameter is too small to get the user SID. /// /// /// ERROR_UNKNOWN_PRODUCT /// The product is not installed on the computer in the specified context. /// /// /// ERROR_FUNCTION_FAILED /// An unexpected internal failure. /// /// /// /// /// /// To enumerate products, an application must initially call the MsiEnumProductsEx function with the iIndex parameter set to /// zero. The application must then increment the iProductIndex parameter and call MsiEnumProductsEx until it returns /// ERROR_NO_MORE_ITEMS and there are no more products to enumerate. /// /// /// When making multiple calls to MsiEnumProductsEx to enumerate all of the products, each call must be made from the same thread. /// /// /// A user must have administrator privileges to enumerate products across all user accounts or a user account other than the /// current user account. The enumeration skips products that are advertised only (such as products not installed) in the /// per-user-unmanaged context when enumerating across all users or a user other than the current user. /// /// Use MsiGetProductInfoEx to get the state or other information about each product instance enumerated by MsiEnumProductsEx. /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumproductsexa UINT MsiEnumProductsExA( LPCSTR szProductCode, // LPCSTR szUserSid, DWORD dwContext, DWORD dwIndex, CHAR [39] szInstalledProductCode, MSIINSTALLCONTEXT *pdwInstalledContext, LPSTR // szSid, LPDWORD pcchSid ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumProductsExA")] public static extern Win32Error MsiEnumProductsEx([Optional, MarshalAs(UnmanagedType.LPTStr)] string szProductCode, [Optional, MarshalAs(UnmanagedType.LPTStr)] string szUserSid, MSIINSTALLCONTEXT dwContext, uint dwIndex, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder szInstalledProductCode, [Out, Optional] IntPtr pdwInstalledContext, [Out, Optional] IntPtr szSid, [Out, Optional] IntPtr pcchSid); /// /// The MsiEnumProductsEx function enumerates through one or all the instances of products that are currently advertised or /// installed in the specified contexts. This function supersedes MsiEnumProducts. /// /// /// ProductCode GUID of the product to be enumerated. Only instances of products within the scope of the context specified by the /// szUserSid and dwContext parameters are enumerated. This parameter can be set to NULL to enumerate all products in the /// specified context. /// /// /// /// Null-terminated string that specifies a security identifier (SID) that restricts the context of enumeration. The special SID /// string s-1-1-0 (Everyone) specifies enumeration across all users in the system. A SID value other than s-1-1-0 is considered a /// user-SID and restricts enumeration to the current user or any user in the system. This parameter can be set to NULL to /// restrict the enumeration scope to the current user. /// /// /// /// SID type /// Meaning /// /// /// NULL /// Specifies the currently logged-on user. /// /// /// User SID /// Specifies enumeration for a particular user in the system. An example of user SID is "S-1-3-64-2415071341-1358098788-3127455600-2561". /// /// /// s-1-1-0 /// Specifies enumeration across all users in the system. /// /// /// /// Note The special SID string s-1-5-18 (System) cannot be used to enumerate products or patches installed as per-machine. /// When dwContext is set to MSIINSTALLCONTEXT_MACHINE only, szUserSid must be NULL. /// /// /// /// /// Restricts the enumeration to a context. This parameter can be any one or a combination of the values shown in the following table. /// /// /// /// Context /// Meaning /// /// /// MSIINSTALLCONTEXT_USERMANAGED /// /// Enumeration extended to all per–user–managed installations for the users specified by szUserSid. An invalid SID returns no items. /// /// /// /// MSIINSTALLCONTEXT_USERUNMANAGED /// /// Enumeration extended to all per–user–unmanaged installations for the users specified by szUserSid. An invalid SID returns no items. /// /// /// /// MSIINSTALLCONTEXT_MACHINE /// /// Enumeration extended to all per-machine installations. When dwInstallContext is set to MSIINSTALLCONTEXT_MACHINE only, the /// szUserSID parameter must be NULL. /// /// /// /// /// /// A sequence of tuples which contain: /// /// /// szInstalledProductCode /// The string value of the ProductCode GUID of the product instance being enumerated. /// /// /// pdwInstalledContext /// The context of the product instance being enumerated. /// /// /// szSid /// /// The string SID of the account under which this product instance exists or for an instance installed in a /// per-machine context. /// /// /// /// public static IEnumerable<(string productCode, MSIINSTALLCONTEXT context, string sidString)> MsiEnumProductsEx( [Optional] string szProductCode, string szUserSid = null, MSIINSTALLCONTEXT dwContext = MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_ALL) { StringBuilder prodCode = new StringBuilder(MAX_GUID_CHARS + 1); StringBuilder sid = new StringBuilder(1024); for (uint i = 0; true; i++) { prodCode.Length = 0; sid.Length = 0; var sidSz = (uint)sid.Capacity; var err = MsiEnumProductsEx(szProductCode, szUserSid, dwContext, i, prodCode, out var ctx, sid, ref sidSz); if (err == Win32Error.ERROR_MORE_DATA) { sid.Capacity = (int)sidSz; err = MsiEnumProductsEx(szProductCode, szUserSid, dwContext, i, prodCode, out ctx, sid, ref sidSz); } if (err == Win32Error.ERROR_NO_MORE_ITEMS) yield break; err.ThrowIfFailed(); yield return (prodCode.ToString(), ctx, sidSz == 0 ? null : sid.ToString()); } } /// /// The MsiEnumRelatedProducts function enumerates products with a specified upgrade code. This function lists the currently /// installed and advertised products that have the specified UpgradeCode property in their Property table. /// /// /// The null-terminated string specifying the upgrade code of related products that the installer is to enumerate. /// /// This parameter is reserved and must be 0. /// The zero-based index into the registered products. /// /// A buffer to receive the product code GUID. This buffer must be 39 characters long. The first 38 characters are for the GUID, and /// the last character is for the terminating null character. /// /// /// /// /// Value /// Meaning /// /// /// ERROR_BAD_CONFIGURATION /// The configuration data is corrupt. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter was passed to the function. /// /// /// ERROR_NO_MORE_ITEMS /// There are no products to return. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// The system does not have enough memory to complete the operation. Available starting with Windows Server 2003. /// /// /// ERROR_SUCCESS /// A value was enumerated. /// /// /// /// /// See UpgradeCode property. /// /// To enumerate currently installed and advertised products that have a specific upgrade code, an application should initially call /// the MsiEnumRelatedProducts function with the iProductIndex parameter set to zero. The application should then increment /// the iProductIndex parameter and call MsiEnumRelatedProducts until the function returns ERROR_NO_MORE_ITEMS, which means /// there are no more products with the specified upgrade code. /// /// /// When making multiple calls to MsiEnumRelatedProducts to enumerate all of the related products, each call should be made /// from the same thread. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/msi/nf-msi-msienumrelatedproductsa UINT MsiEnumRelatedProductsA( LPCSTR // lpUpgradeCode, DWORD dwReserved, DWORD iProductIndex, LPSTR lpProductBuf ); [DllImport(Lib_Msi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("msi.h", MSDNShortId = "NF:msi.MsiEnumRelatedProductsA")] public static extern Win32Error MsiEnumRelatedProducts([MarshalAs(UnmanagedType.LPTStr)] string lpUpgradeCode, [Optional] uint dwReserved, uint iProductIndex, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpProductBuf); } }