Using MsiQueryProductStateA in VB.NET RRS feed

  • Question

  • Howdy,

    Got some questions:

    1st I use this code but INSTALLSTATE is not defined, how to eliminate the error?

    Imports System
    Imports System.Runtime.InteropServices
    Private Declare Function MsiQueryProductState Lib "msi.dll" (ByVal product As String) As INSTALLSTATE
    Dim state As INSTALLSTATE = QueryProductState.MsiQueryProductState("{1D8E6291-B0D5-35EC-8441-6616F567A0F7}")

    2n What's the difference between MsiQueryProductStateA & MsiQueryProductStateW? MSDN has the same description for both! Great Documentation!

    Thanks, the above code is to detect the presence of VC++ 2010.
    Unfortunately the registry method mentioned here:

    Does NOT work for VC++ 2010 SP1.1 Version 10.0.40219!

    Sunday, January 6, 2019 1:08 PM

All replies

  • INSTALLSTATE is an Enum. Have never used this API so that is my extent of assistance.

    Public Enum INSTALLSTATE
        ''' <summary>
        ''' Component disabled.
        ''' </summary>
        NOTUSED = -7
        ''' <summary>
        ''' Configuration data corrupt.
        ''' </summary>
        BADCONFIG = -6
        ''' <summary>
        ''' Installation suspended or in progress.
        ''' </summary>
        INCOMPLETE = -5
        ''' <summary>
        ''' Run from source, source is unavailable.
        ''' </summary>
        SOURCEABSENT = -4
        ''' <summary>
        ''' Return buffer overflow.
        ''' </summary>
        MOREDATA = -3
        ''' <summary>
        ''' Invalid function argument.
        ''' </summary>
        INVALIDARG = -2
        ''' <summary>
        ''' Unrecognized product or feature.
        ''' </summary>
        UNKNOWN = -1
        ''' <summary>
        ''' Broken.
        ''' </summary>
        BROKEN = 0
        ''' <summary>
        ''' Advertised feature.
        ''' </summary>
        ADVERTISED = 1
        ''' <summary>
        ''' Component being removed (action state, not settable).
        ''' </summary>
        REMOVED = 1
        ''' <summary>
        ''' Uninstalled (or action state absent but clients remain).
        ''' </summary>
        ABSENT = 2
        ''' <summary>
        ''' Installed on local drive.
        ''' </summary>
        LOCAL = 3
        ''' <summary>
        ''' Run from source, CD or net.
        ''' </summary>
        SOURCE = 4
        ''' <summary>
        ''' use default, local or source
        ''' </summary>
        [DEFAULT] = 5
    End Enum

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, January 6, 2019 1:57 PM
  • Oh thanks, didn't know that, now I get another error: 'QueryProductState' is not declared. It may be inaccessible due to its protection level. Any idea?
    Sunday, January 6, 2019 2:48 PM
  • Oh thanks, didn't know that, now I get another error: 'QueryProductState' is not declared. It may be inaccessible due to its protection level. Any idea?

    Remove QueryProductState.
    Sunday, January 6, 2019 3:13 PM
  • I already tried that, removing that will eliminate all errors, but causes a runtime EntryPointNotFound Exception:

    Unable to find an entry point named 'MsiQueryProductState' in DLL 'msi.dll'.

    Sunday, January 6, 2019 4:15 PM
  • Try this declaration:

    Private Declare Unicode Function MsiQueryProductState Lib "msi" Alias "MsiQueryProductStateW" (ByVal product As String) As INSTALLSTATE

    Sunday, January 6, 2019 4:24 PM
  • or :

        <DllImport("Msi.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
        Public Shared Function MsiQueryProductState(szProduct As String) As INSTALLSTATE
        End Function

    Sunday, January 6, 2019 4:33 PM
  • Thanks, it worked :)

    Just a side question: I checked {1D8E6291-B0D5-35EC-8441-6616F567A0F7} which is for VC++ 2010 x64 SP1 and it returned 5 DEFAULT, it's installed, so it should return maybe 3, installed on local drive?! This function has many confusing enums!

    Sunday, January 6, 2019 5:10 PM
  • Hi,

    see the following link,3 or 5 can judge that it has been installed.

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, January 8, 2019 3:20 AM