473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

MsiGetUserInfo Implementation

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
*-----------------------*
Nov 21 '05 #1
4 1046
YenPei,

Is this for dotnet, because for dotnet is the registry class?

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps?

Cor
Nov 21 '05 #2
<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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #3
Thanks. The StringBuilder works but I still keep the Long.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 21 '05 #4
but I still keep the Long.


Why? It's not correct.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
29
by: Enrico `Trippo' Porreca | last post by:
Both K&R book and Steve Summit's tutorial define a getline() function correctly testing the return value of getchar() against EOF. I know that getchar() returns EOF or the character value cast to...
52
by: lovecreatesbeauty | last post by:
Why the C standard committee doesn't provide a standard implementation including the C compiler and library when the language standard document is published? C works on the abstract model of low...
20
by: Luc Kumps | last post by:
(Sorry about the previous post, it got transmitted before it was complete) We try to separate implementation and interface defintions, but we run into a problem. I hope the guru's can solve this,...
7
by: desktop | last post by:
I the C++ standard page 472 it says that an associative container can be constructed like X(i,j,c) where i and j are input iterators to elements. But in the implementation there is no constructor...
6
by: Ralph | last post by:
Hi, I was reading effictive C++ and some other books again and they all tell you about hiding implementation details (proxy/pimpl/inheritance) but they never really explain when to use it. I...
0
by: anto.anish | last post by:
Hi , Since, i did not want to write instantiations in Source file of all template methods for various different datatypes that my client might use, i choose to write implementation of template...
1
by: anto.anish | last post by:
Hi , Since, i did not want to write explicit instantiations in Source file of all template methods for various different datatypes that my client might use, i choose to write implementation of...
173
by: Ron Ford | last post by:
I'm looking for a freeware c99 compiler for windows. I had intended to use MS's Visual C++ Express and use its C capability. In the past with my MS products, I've simply needed to make .c the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.