1
Detect if my product is installedIsProductInstalled
doesn't do much. It simply decorates and invokes system API
IsProductInstalled
. Thus if it doesn't return what you expect then most likely your
projectGUID
is not correct. You can have a look at
GenericTest.AppSearchTest
of WixSharp.Test projhect where IsProductInstalled is used to check if product "Windows Live Photo Common" is installed.
[DllImport("msi", CharSet = CharSet.Unicode)]
staticextern Int32 MsiGetProductInfo(string product, string property, [Out] StringBuilder valueBuf, ref Int32 len);
staticpublicbool IsProductInstalled(string productCode)
{
var productNameLen = 512;
var productName = new StringBuilder(productNameLen);
if (0 == MsiGetProductInfo(productCode, "ProductName", productName, ref productNameLen))
return !string.IsNullOrEmpty(productName.ToString());
elsereturnfalse;
}
2 Assming you fixed your problem with productCode you can invoke MsiGetProductInfo with
"Version"
and it will return you a string of the DWORD value for
version. You can slice it to extract the version components.
The latest code of WixSharp.AppSearch (use git if you need to see it) already has an API for this:
staticpublic Version GetProductVersion(string productCode)
{
var versionStr = GetProductInfo(productCode, "Version");
//MMmmBBBBif (versionStr.IsNotEmpty())
{
int value;
if (int.TryParse(versionStr, out value))
{
var major = (int)(value & 0xFF000000) >> 8 * 3;
var minor = (int)(value & 0x00FF0000) >> 8 * 2;
var build = (int)(value & 0x0000FFFF);
returnnew Version(major, minor, build);
}
}
returnnull;
}
3
Where can I save the data?
Anywhere you want. It's C# you can do anything you want. I guess some well-known locations (file system, registry...) can be an obvious choice.