If Outlook has "hard disabled" an addin the only way to get it re-enabled
without the user re-enabling it from the Disabled Items dialog is to delete
the resiliency key in the registry when Outlook is not running or force a
restart. Merely changing the LoadBehavior value is not sufficient. And
deleting the resiliency key is not a good thing since it will also re-enable
any other disabled addins.
In addition, distributing an OTM file is also not the best way to go, that
overwrites any OTM file the user may have. If your code did that to my
Outlook VBA project I'd rip it out and never install it ever again.
You should handle all exceptions and use defensive programming where
possible to avoid any exceptions, that's the way to not get disabled.
We had the same problem, therefore we also distribute a signed otm
file with our VSTO Addins For Outlook.
In the Application_Startup Event of the Application object inside our
otm file,
we check the registry entries for particular addins and if the addin
has been disabled , we change the registry settings correspondingly to
the normal state and force a restart in outlook with Application.Quit
command.
Public Function CheckOutlookAddins(SourceApplication As Application)
Dim csfKey As String
csfKey = RegRead(HKEY_CURRENT_USER, "Software\Nowhere\NoWhereAddin",
"CheckReinstall")
If csfKey = "1" Then
On Error GoTo Cleanup
Set generalApplication = SourceApplication
Dim outlookApplication As Application
Set outlookApplication = SourceApplication
Dim correctionResult As Boolean
Dim addinCount As Integer
Dim foundAddin As COMAddIn
addinCount = outlookApplication.COMAddIns.Count
For i = 1 To addinCount
If outlookApplication.COMAddIns(i).Description = CSFDescription
Then
Set foundAddin = outlookApplication.COMAddIns(i)
If Not foundAddin.Connect Then
On Error Resume Next
foundAddin.Connect = True
If Err.Number <> 0 Then
Err.Clear
Set foundAddin = Nothing
End If
On Error GoTo Cleanup
Exit For
Else
Exit For
End If
End If
Next
'Everything Running Fine Exit Loop
If foundAddin Is Nothing Then
Dim processResult As CreationStates
processResult = ProcessRegistryKeys()
Select Case processResult
Case CreationStates.CreationSuccess
If Not CheckOutlookAddinsStandalone(SourceApplication,
False) Then
CheckOutlookAddinsStandalone SourceApplication, True
End If
Case CreationStates.DllIsMissing
MsgBox ("Addin Dlls Missing. Registry Key Will Be
Disabled")
RegWrite HKEY_CURRENT_USER, "Software\Nowhere
\NoWhereAddin", "CheckReinstall", "0"
Exit Function
Case Else
GoTo Cleanup
End Select
Else
CorrectAddinStructure SourceApplication, foundAddin
End If
Exit Function
Cleanup:
Set outlookApplication = Nothing
Set generalApplication = Nothing
Set foundAddin = Nothing
MsgBox GetCurrentLanguageFromParameters & Err.Description
End If
End Function