Using the Windows installer object to get upgrade code
Hello
At the moment I am using a VB Script to call the installer object to get the Product code to figure out if the application is installed. I am going though the process of updating the package to the next version and want to know if it’s possible to change it from using the Product code to search for to the Upgrade code so I only have to look for one variable in the code instead of looking for two variables.
Here is the following code I am using to get the product code:
At the moment I am using a VB Script to call the installer object to get the Product code to figure out if the application is installed. I am going though the process of updating the package to the next version and want to know if it’s possible to change it from using the Product code to search for to the Upgrade code so I only have to look for one variable in the code instead of looking for two variables.
Here is the following code I am using to get the product code:
Function PackageInstalled (ProductCode)
Dim ProductState
ProductState – installer.productState (DSWT505ProductCode)
If ProductState <> INSTALLSTATE_LOCAL AND ProductState <> INSTALLSTATE_ADVERTISED And ProductState <> INSTALLSTATE_DEFAULT THEN
Package Installed = false
Else
PackageInstalled=true
End if
End function
0 Comments
[ + ] Show comments
Answers (10)
Please log in to answer
Posted by:
anonymous_9363
15 years ago
I think you'll need to dig a bit deeper as, IIRC, ProductState returns INSTALLSTATE_DEFAULT only for the currently logged-in user.If all your apps are installed per-machine, all well and good but if any are installed per-user and you query for an app installed by someone other than the current user, it'll return INSTALLSTATE_ABSENT.
EDIT:
Found this discussion http://forum.installsite.net/index.php?act=ST&f=26&t=14035
EDIT2:
Out of curiosity, I re-read the MSDN entry on ProductState. INSTALLSTATE_ABSENT means that is *is* installed but not for the current user. Not installed at all returns INSTALLSTATE_UNKNOWN.
EDIT:
Found this discussion http://forum.installsite.net/index.php?act=ST&f=26&t=14035
EDIT2:
Out of curiosity, I re-read the MSDN entry on ProductState. INSTALLSTATE_ABSENT means that is *is* installed but not for the current user. Not installed at all returns INSTALLSTATE_UNKNOWN.
Posted by:
ditch_nz
15 years ago
Posted by:
jmcfadyen
15 years ago
Posted by:
anonymous_9363
15 years ago
use the .productsEx methods it works across multiple user hives (i.e. per user)I wonder why MSDN doesn't SAY that? It simply says that it returns a RecordList of installed products. The entry for the 'Products' property states that it enumerates (to a StringList) all products installed for the current user, so it's curious that ProductsEx doesn't make the distinction clear.
Anyway, good to know, John. Nice one.
Posted by:
AngelD
15 years ago
Posted by:
anonymous_9363
15 years ago
Ok, so now I'm wondering why a search on MSDN for 'ProductsEx' (another unfortunate choice of nomenclature, right up there with 'expertsexchange'... think about it...) doesn't turn up a method, only the property? http://msdn.microsoft.com/en-us/library/aa369461(VS.85).aspx
Posted by:
AngelD
15 years ago
You're correct Ian!
ProductsEx refer to as a property for the Installer object; the actual function/method doing the work is MsiEnumProductsEx.
My guessing is that you can still use the Installer.ProductState(<ProductCode>) to find out if the product is installed; msiInstallStateAbsent (The product is installed for a different user) and msiInstallStateDefault (The product is advertised but not installed).
However I would just populate the Upgrade table to handle the "upgrade" for the next version.
Just keep in mind to use the same ALLUSERS; per-machine or per-user.
ProductsEx refer to as a property for the Installer object; the actual function/method doing the work is MsiEnumProductsEx.
My guessing is that you can still use the Installer.ProductState(<ProductCode>) to find out if the product is installed; msiInstallStateAbsent (The product is installed for a different user) and msiInstallStateDefault (The product is advertised but not installed).
However I would just populate the Upgrade table to handle the "upgrade" for the next version.
Just keep in mind to use the same ALLUSERS; per-machine or per-user.
Posted by:
jmcfadyen
15 years ago
sorry i meant thos ..
set objInstaller = CreateObject("WindowsInstaller.Installer")
For Each objProduct In objInstaller.ProductsEx("", "", 7)
strProductCode = objProduct.ProductCode
strUserSid = objProduct.UserSid
strSource = objInstaller.ProductInfo(strProductCode, "Installsource")
msgbox objProduct.ProductCode & strSource
exit for
Next
similar code to what you want. , you basically trawl through the installer object like so.
this will present you with product codes that are installed.
set objInstaller = CreateObject("WindowsInstaller.Installer")
For Each objProduct In objInstaller.ProductsEx("", "", 7)
strProductCode = objProduct.ProductCode
strUserSid = objProduct.UserSid
strSource = objInstaller.ProductInfo(strProductCode, "Installsource")
msgbox objProduct.ProductCode & strSource
exit for
Next
similar code to what you want. , you basically trawl through the installer object like so.
this will present you with product codes that are installed.
Posted by:
jmcfadyen
15 years ago
oh one other thing, i thought it was a method, obviously mistaken I don't use it much but its quite handy.
detects per user installs as well, in the above example I had a per user install with no source paths i needed to update to stop the dreaded browse window appearing for everyone.
poor planning p1sses me off sometimes.. :-)
detects per user installs as well, in the above example I had a per user install with no source paths i needed to update to stop the dreaded browse window appearing for everyone.
poor planning p1sses me off sometimes.. :-)
Posted by:
anonymous_9363
15 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.