cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ReinstallFeature method of the Installer object

How can I tell if calling the ReinstallFeature method of the Installer object has successfully completed?
This method does not return a value.

If I use:
err.Clear
oInstaller.ReinstallFeature Product,Feature,256
If err.Number = 0 Then
MsgBox "Success"
Else
MsgBox "Failed" & vbcrlf & err.Number & vbcrlf & err.Description
End If

Sometimes the err.number is -2147467259 on calls that have appeared to be successful.
The description is "ReinstallFeature,Product,Feature,ReinstallMode"

ALSO If I run msiexec /iProductCode REINSTALL=Feature /l*v "C:\f.log"
The log file does not contain the error number above and the reinstall was successful.
(3) Replies
I think your safest option is to write an MSI custom action DLL and call the MsiReinstallFeature API. This has better return values and can give you extended error information as well.
Using VB, I made a call to MsiReinstallFeatureA and grabbed the return value.
Unfortunately, my attempt to retrieve the ProductName property with a call to MsiGetProductInfoW did not yield any results. I was forced to grab the name from the \installer\Products key.
This is how I got MsiReinstallFeatureA & MsiGetProductInfo to work in VB
Many Thank to Robert Dickau for his help.

(General)
Private Declare Function MsiReinstallFeatureA Lib "msi.dll" (ByVal szProduct As String, ByVal szFeature As String, ByVal dwReinstallMode As Long) As Long
Private Declare Function MsiGetProductInfo Lib "msi.dll" Alias "MsiGetProductInfoA" (ByVal szProduct As String, ByVal szAttribute As String, ByVal lpValueBuf As Long, ByRef pcchValueBuf As Long) As Integer
Const ERROR_SUCCESS = 0
Const ERROR_SUCCESS_REBOOT_INITIATED = 1641
Const ERROR_SUCCESS_REBOOT_REQUIRED = 3010
Dim datalen As Long
Dim ValName As String
Dim retval As Long

Private Sub Form_Load()
Call ReinstallFeature("{90110409-6000-11D3-8CFE-0150048383C9}","EXCELFiles")
End Sub

Public Function ReinstallFeature(sGUID as String,sFeatureName as String)
retval = MsiReinstallFeatureA(sGUID, sFeatureName,REINSTALLMODE_USERDATA)
Select Case retval
'Report only successful feature reinstallations
Case ERROR_SUCCESS, ERROR_SUCCESS_REBOOT_INITIATED, ERROR_SUCCESS_REBOOT_REQUIRED
MsiGetProductInfo aInstall(x, 0), "InstalledProductName", StrPtr(ValName), datalen
ValName = StrConv(Left(ValName, datalen), vbUnicode, datalen)
MsgBox ValName & " feature " & sFeatureName & " has been successfully reinstalled"

Case Else
' perform some type of error handling
End Select
End Function