From: Phil Wilson on
I checked a VS 2008 setup project - the serial number does in fact use the
PIDKEY property, and goes through the validation as here:

http://msdn.microsoft.com/en-us/library/aa370826(VS.85).aspx

so that MsiGetProductInfo() should work. I just tried this on a test setup
and it worked fine, retrieving the entered serial, C++:

DWORD bLen=256;
WCHAR buf [256] = {0};
UINT res = MsiGetProductInfo (L"{05E6800C-619C-44FB-A5CE-B40677CFE5B8}", //
ProductCode
L"ProductID",
buf, &bLen);

--
Phil Wilson

"John Whitworth" <sexyjw(a)g_EEEEEEEEEEEEEEEE_mail.com> wrote in message
news:4b485d48$0$2529$da0feed9(a)news.zen.co.uk...
>
>
> "Wilson, Phil" <philw(a)wonderware.nospam.com> wrote in message
> news:5B236C0F-1020-4668-AABF-E2E2187A968D(a)microsoft.com...
>> Assuming Visual Studio installers do the standard thing, use
>> MsiGetProductInfo and ask for "ProductID", as here:
>>
>> http://msdn.microsoft.com/en-us/library/aa370130(VS.85).aspx
>>
>> Or (again assuming standard behavior) the key is associated with the
>> PIDKEY property, so you can write [PIDKEY] to the registry using the
>> setup project's IDE.
>
> Thanks Phil. I tried to do both of those things last night, and got
> horribly lost. I will investigate further later on.
>
> JW


From: John Whitworth on
Great - thanks Phil. I will have a go at that now. Mine's a VB project, but
should be able to do it.

John

"Phil Wilson" <pdjwilson(a)nospam.cox.net> wrote in message
news:edRDPxVkKHA.3792(a)TK2MSFTNGP02.phx.gbl...
> I checked a VS 2008 setup project - the serial number does in fact use the
> PIDKEY property, and goes through the validation as here:
>
> http://msdn.microsoft.com/en-us/library/aa370826(VS.85).aspx
>
> so that MsiGetProductInfo() should work. I just tried this on a test setup
> and it worked fine, retrieving the entered serial, C++:
>
> DWORD bLen=256;
> WCHAR buf [256] = {0};
> UINT res = MsiGetProductInfo (L"{05E6800C-619C-44FB-A5CE-B40677CFE5B8}",
> // ProductCode
> L"ProductID",
> buf, &bLen);
>
> --
> Phil Wilson
>
> "John Whitworth" <sexyjw(a)g_EEEEEEEEEEEEEEEE_mail.com> wrote in message
> news:4b485d48$0$2529$da0feed9(a)news.zen.co.uk...
>>
>>
>> "Wilson, Phil" <philw(a)wonderware.nospam.com> wrote in message
>> news:5B236C0F-1020-4668-AABF-E2E2187A968D(a)microsoft.com...
>>> Assuming Visual Studio installers do the standard thing, use
>>> MsiGetProductInfo and ask for "ProductID", as here:
>>>
>>> http://msdn.microsoft.com/en-us/library/aa370130(VS.85).aspx
>>>
>>> Or (again assuming standard behavior) the key is associated with the
>>> PIDKEY property, so you can write [PIDKEY] to the registry using the
>>> setup project's IDE.
>>
>> Thanks Phil. I tried to do both of those things last night, and got
>> horribly lost. I will investigate further later on.
>>
>> JW
>
>
From: John Whitworth on




"John Whitworth" <sexyjw(a)g_EEEEEEEEEEEEEEEE_mail.com> wrote in message
news:4b4906ce$0$2488$db0fefd9(a)news.zen.co.uk...
> Superb! It does work...obviously only on a properly installed version
> though, and is blank for the VS-hosted version. So one more question...can
> I get my application to be aware of when it's running within VS? So that
> when my validation is in place, I don't get 'invalid Product ID" every
> time I run?
>

Just in case anyone wants to do this in the future, I've now corrected the
code, courtesy of Armin Zingler, from the dotnet.languages.vb newsgroup.

The correct code is below:

Declare Auto Function MsiGetProductInfo Lib "msi.dll" (ByVal product As
String, ByVal [property] As String, <MarshalAs(UnmanagedType.LPTStr)> ByVal
valueBuf As String, ByRef len As UInteger) As UInteger


Public ProdID = New String(" ", 255)
Public RegOwn = New String(" ", 255)
Public ProdIDLen As UInteger = 255
Public RegOwnLen As UInteger = 255

Private Sub MainForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

MsiGetProductInfo("{9459583F-02E4-4971-B3B7-E2235F41F477}",
"ProductID", ProdID, ProdIDLen)
MsiGetProductInfo("{9459583F-02E4-4971-B3B7-E2235F41F477}",
"RegOwner", RegOwn, RegOwnLen)

>
>
>
> "Phil Wilson" <pdjwilson(a)nospam.cox.net> wrote in message
> news:edRDPxVkKHA.3792(a)TK2MSFTNGP02.phx.gbl...
>> I checked a VS 2008 setup project - the serial number does in fact use
>> the PIDKEY property, and goes through the validation as here:
>>
>> http://msdn.microsoft.com/en-us/library/aa370826(VS.85).aspx
>>
>> so that MsiGetProductInfo() should work. I just tried this on a test
>> setup and it worked fine, retrieving the entered serial, C++:
>>
>> DWORD bLen=256;
>> WCHAR buf [256] = {0};
>> UINT res = MsiGetProductInfo (L"{05E6800C-619C-44FB-A5CE-B40677CFE5B8}",
>> // ProductCode
>> L"ProductID",
>> buf, &bLen);
>>
>> --
>> Phil Wilson
>>
>> "John Whitworth" <sexyjw(a)g_EEEEEEEEEEEEEEEE_mail.com> wrote in message
>> news:4b485d48$0$2529$da0feed9(a)news.zen.co.uk...
>>>
>>>
>>> "Wilson, Phil" <philw(a)wonderware.nospam.com> wrote in message
>>> news:5B236C0F-1020-4668-AABF-E2E2187A968D(a)microsoft.com...
>>>> Assuming Visual Studio installers do the standard thing, use
>>>> MsiGetProductInfo and ask for "ProductID", as here:
>>>>
>>>> http://msdn.microsoft.com/en-us/library/aa370130(VS.85).aspx
>>>>
>>>> Or (again assuming standard behavior) the key is associated with the
>>>> PIDKEY property, so you can write [PIDKEY] to the registry using the
>>>> setup project's IDE.
>>>
>>> Thanks Phil. I tried to do both of those things last night, and got
>>> horribly lost. I will investigate further later on.
>>>
>>> JW
>>
>>
From: Jamesb on
So one more
> question...can I get my application to be aware of when it's running
> within VS? So that when my validation is in place, I don't get 'invalid
> Product ID" every time I run?

You can use the System.Diagnostics.Debugger.IsAttached property:

http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.isattached.aspx


Or use the DEBUG pre-compiler constant. e.g.

#If DEBUG Then
' Don't do your Product Id Check
#Else
' Do your Product Id Check Here
#End If

Both approaches come in useful.

Another handy thing is the Debug.Assert statement.

You can code something like:

Debug.Assert(DebugLogging())

The function DebugLogging will the only be called in debug mode. When
the code is built in release mode it won't be called.
From: John Whitworth on


"Jamesb" <spam(a)gmail.com> wrote in message
news:00802f9e$0$9625$c3e8da3(a)news.astraweb.com...
> So one more
>> question...can I get my application to be aware of when it's running
>> within VS? So that when my validation is in place, I don't get 'invalid
>> Product ID" every time I run?
>
> You can use the System.Diagnostics.Debugger.IsAttached property:
>
> http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.isattached.aspx
>
>
> Or use the DEBUG pre-compiler constant. e.g.
>
> #If DEBUG Then
> ' Don't do your Product Id Check
> #Else
> ' Do your Product Id Check Here
> #End If
>
> Both approaches come in useful.
>
> Another handy thing is the Debug.Assert statement.
>
> You can code something like:
>
> Debug.Assert(DebugLogging())
>
> The function DebugLogging will the only be called in debug mode. When
> the code is built in release mode it won't be called.

Thanks Jamesb. I'll put some of that to good use right now. And will
squirrel the whole mail away for future use.

John