Exemple #1
0
 public static extern unsafe Win32ErrorCode MsiEnumProductsEx(
     string szProductCode,
     string szUserSid,
     MSIINSTALLCONTEXT dwContext,
     int dwIndex,
     [Friendly(FriendlyFlags.Out | FriendlyFlags.Optional | FriendlyFlags.Array)] char *szInstalledProductCode,
     [Friendly(FriendlyFlags.Out | FriendlyFlags.Optional)] MSIINSTALLCONTEXT *pdwInstalledContext,
     [Friendly(FriendlyFlags.Out | FriendlyFlags.Optional | FriendlyFlags.Array)] char *szSid,
     [Friendly(FriendlyFlags.In | FriendlyFlags.Out | FriendlyFlags.Optional)] int *pcchSid);
Exemple #2
0
 public static extern unsafe Win32ErrorCode MsiEnumProductsEx(
     string szProductCode,
     string szUserSid,
     MSIINSTALLCONTEXT dwContext,
     int dwIndex,
     [Friendly(FriendlyFlags.Out | FriendlyFlags.Optional | FriendlyFlags.Array)] char* szInstalledProductCode,
     [Friendly(FriendlyFlags.Out | FriendlyFlags.Optional)] MSIINSTALLCONTEXT* pdwInstalledContext,
     [Friendly(FriendlyFlags.Out | FriendlyFlags.Optional | FriendlyFlags.Array)] char* szSid,
     [Friendly(FriendlyFlags.In | FriendlyFlags.Out | FriendlyFlags.Optional)] int* pcchSid);
Exemple #3
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="szProductCode">
        /// 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.
        /// </param>
        /// <param name="szUserSid">
        /// 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.
        /// See MSDN documentation for more information.
        /// </param>
        /// <param name="dwContext">Restricts the enumeration to a context. </param>
        /// <param name="dwIndex">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.</param>
        /// <param name="szInstalledProductCode">Gives the ProductCode GUID of the product instance being enumerated. This parameter can be NULL.</param>
        /// <param name="pdwInstalledContext">Returns the context of the product instance being enumerated. The output value can be <see cref="MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_USERMANAGED"/>, <see cref="MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_USERUNMANAGED"/>, or <see cref="MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_MACHINE"/>. This parameter can be NULL.</param>
        /// <param name="szSid">
        /// 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.
        /// </param>
        /// <returns>An error code.</returns>
        public static unsafe Win32ErrorCode MsiEnumProductsEx(
            string szProductCode,
            string szUserSid,
            MSIINSTALLCONTEXT dwContext,
            int dwIndex,
            out Guid szInstalledProductCode,
            out MSIINSTALLCONTEXT pdwInstalledContext,
            out string szSid)
        {
            szInstalledProductCode = Guid.Empty;
            pdwInstalledContext    = MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_NONE;
            szSid = null;

            var installedProductCode = new char[39];
            MSIINSTALLCONTEXT?pdwInstalledContextLocal = MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_NONE;
            int?           pcchSid = 0;
            Win32ErrorCode error   = MsiEnumProductsEx(
                szProductCode,
                szUserSid,
                dwContext,
                dwIndex,
                installedProductCode,
                ref pdwInstalledContextLocal,
                null,
                ref pcchSid);

            if (error != Win32ErrorCode.ERROR_SUCCESS)
            {
                return(error);
            }

            char[] pszSid = new char[pcchSid.Value];
            error = MsiEnumProductsEx(
                szProductCode,
                szUserSid,
                dwContext,
                dwIndex,
                installedProductCode,
                ref pdwInstalledContextLocal,
                pszSid,
                ref pcchSid);
            if (error != Win32ErrorCode.ERROR_SUCCESS)
            {
                return(error);
            }

            szInstalledProductCode = new Guid(new string(installedProductCode, 0, 38));
            pdwInstalledContext    = pdwInstalledContextLocal.Value;
            szSid = new string(pszSid, 0, pcchSid.Value);
            return(error);
        }
Exemple #4
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="szProductCode">
        /// 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.
        /// </param>
        /// <param name="szUserSid">
        /// 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.
        /// See MSDN documentation for more information.
        /// </param>
        /// <param name="dwContext">Restricts the enumeration to a context. </param>
        /// <param name="dwIndex">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.</param>
        /// <param name="szInstalledProductCode">Gives the ProductCode GUID of the product instance being enumerated. This parameter can be NULL.</param>
        /// <param name="pdwInstalledContext">Returns the context of the product instance being enumerated. The output value can be <see cref="MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_USERMANAGED"/>, <see cref="MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_USERUNMANAGED"/>, or <see cref="MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_MACHINE"/>. This parameter can be NULL.</param>
        /// <param name="szSid">
        /// 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.
        /// </param>
        /// <returns>An error code.</returns>
        public static unsafe Win32ErrorCode MsiEnumProductsEx(
            string szProductCode,
            string szUserSid,
            MSIINSTALLCONTEXT dwContext,
            int dwIndex,
            out Guid szInstalledProductCode,
            out MSIINSTALLCONTEXT pdwInstalledContext,
            out string szSid)
        {
            szInstalledProductCode = Guid.Empty;
            pdwInstalledContext = MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_NONE;
            szSid = null;

            var installedProductCode = new char[39];
            MSIINSTALLCONTEXT? pdwInstalledContextLocal = MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_NONE;
            int? pcchSid = 0;
            Win32ErrorCode error = MsiEnumProductsEx(
                szProductCode,
                szUserSid,
                dwContext,
                dwIndex,
                installedProductCode,
                ref pdwInstalledContextLocal,
                null,
                ref pcchSid);
            if (error != Win32ErrorCode.ERROR_SUCCESS)
            {
                return error;
            }

            char[] pszSid = new char[pcchSid.Value];
            error = MsiEnumProductsEx(
                szProductCode,
                szUserSid,
                dwContext,
                dwIndex,
                installedProductCode,
                ref pdwInstalledContextLocal,
                pszSid,
                ref pcchSid);
            if (error != Win32ErrorCode.ERROR_SUCCESS)
            {
                return error;
            }

            szInstalledProductCode = new Guid(new string(installedProductCode, 0, 38));
            pdwInstalledContext = pdwInstalledContextLocal.Value;
            szSid = new string(pszSid, 0, pcchSid.Value);
            return error;
        }
Exemple #5
0
 private static unsafe string GetSid(MSIINSTALLCONTEXT installContext, char *sid, uint sidSize) =>
 installContext != MSIINSTALLCONTEXT.MSIINSTALLCONTEXT_MACHINE ? new string(sid, 0, (int)sidSize) : null;