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
*-----------------------*