MsiGetUserInfo Implementation

  • Thread starter Thread starter yenpei
  • Start date Start date
Y

yenpei

Hi,

I am trying to retrieve Product ID from the registry using the code
below:


<DllImport("msi.dll", EntryPoint:="MsiGetUserInfo",
SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function GetUserInfo( _
ByVal ProductCode As String, _
ByVal UserName As String, _
ByRef UserNameLen As Long, _
ByVal OrgName As String, _
ByRef OrgNameLen As Long, _
ByVal PID As String, _
ByRef PIDLen As Long) As
USERINFOSTATE

End Function

Public Enum USERINFOSTATE
USERINFOSTATE_MOREDATA = -3
USERINFOSTATE_INVALIDARG = -2
USERINFOSTATE_UNKNOWN = -1
USERINFOSTATE_ABSENT = 0
USERINFOSTATE_PRESENT = 1
End Enum

' Get Product ID (Serial Number)
Dim s As USERINFOSTATE
Dim user As String = "as"
Dim userlen As Long = 100
Dim org As String = "as"
Dim orglen As Long = 100
Dim productserial As String = "as"
Dim productseriallen As Long = 100

s =
Me.MsiGetUserInfo("{1DAA493C-2EFD-41CB-90AD-4EA886864BF9}", user,
userlen, org, orglen, productserial, productseriallen)

If s = USERINFOSTATE.USERINFOSTATE_PRESENT Then
ProductID = productserial
End If


However, at compile time, I got the following error message:

An unhandled exception of type 'System.InvalidProgramException'
occurred in NextWave Doremi Cafe.exe

Additional information: Error: PInvoke item (field,method) must be
Static.


Question: Is there any other way to try to get the Product serial
number during installation time? I am trying to write this serial
number into other registry location.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
<DllImport("msi.dll", EntryPoint:="MsiGetUserInfo",
SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function GetUserInfo( _
ByVal ProductCode As String, _
ByVal UserName As String, _
ByRef UserNameLen As Long, _
ByVal OrgName As String, _
ByRef OrgNameLen As Long, _
ByVal PID As String, _
ByRef PIDLen As Long) As
USERINFOSTATE

The Longs should be changed to Integers. I would also recommend using
StringBuilder instead of String for the output string parameters.

And finally, fo fix the compile error you get, you should make the
method Shared.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top