Page 1 of 1

Outlook COM - Enable or disable add-ins

Posted: 18 Nov 2016, 12:25
by kon
This topic is created on behalf of another user who asked:
Hi , I saw your input here:
https://autohotkey.com/board/topic/7133 ... ntry730111

your code will show me the add-ins installed on my outlook , my question is: is there anyway to disable one of them?
If we convert your code to GUI, will it be possible to add like Button to disable one of the add-ins in my list?

Any help will be appreciated.
Thank you

Re: Outlook COM - Enable or disable add-ins

Posted: 18 Nov 2016, 12:26
by kon
COMAddIn Object wrote:Use the Connect property to set or return the state of the connection to a specified COM add-in.
This is untested. It should be possible to run this from a GUI g-label.

Code: Select all

; **Probably needs to be run as admin** (untested)

olApp := ComObjActive("Outlook.Application")
for COMAddIn, in olApp.COMAddIns
{
    MsgBox, % COMAddIn.Creator "`n"
        . COMAddIn.Description "`n"
        . COMAddIn.Guid "`n"
        . COMAddIn.ProgId "`n"
        . COMAddIn.Connect  ; Dispay add-in state
    
    if (COMAddIn.Guid = "{F37AFD4F-E736-4980-8650-A486B1F2DF25}")  ; GUID for Windows Search Email Indexer add-in
        COMAddIn.Connect := -1  ; 0 for false, -1 for true
    
    MsgBox, % COMAddIn.Creator "`n" 
        . COMAddIn.Description "`n"
        . COMAddIn.Guid "`n"
        . COMAddIn.ProgId "`n"
        . COMAddIn.Connect  ; Dispay add-in state
}

Re: Outlook COM - Enable or disable add-ins

Posted: 18 Nov 2016, 15:23
by Rami
Hi Kon,
Thank you for your response.

Unfortunately it doesn't work for me, I did add all your code in g-label,
I don't know why I cannot upload images in the forum, anyway, the error is on line:
COMAddIn.Connect := -1
Error: 0x80004004 - Operation aborted

I used to run commands, and functions when click, or to delete, but i have zero knowledge in COM stuff :) Can you please help me more to add GUI and how to chose what add-in to disable in that GUI?
appreciate your time.

Re: Outlook COM - Enable or disable add-ins

Posted: 18 Nov 2016, 15:29
by Rami
Or, if it is easier , just to disable one certain add-in , i know its name and the dll file

Thank you

Re: Outlook COM - Enable or disable add-ins  Topic is solved

Posted: 18 Nov 2016, 15:40
by kon
Not sure why you get that error.
I don't have access to Outlook on an admin account so I can't test at the moment.

Code: Select all

; **Probably needs to be run as admin** (untested)

Gui, Add, ListView, vLV1 w800 h300, Connected|Description|ProgId|GUID
Gui, Add, Button, vB1 gToggleSelected w80, Toggle
Gui, Show
Refresh()
return

GuiClose() {
    ExitApp
}

OutlookConnect() {
    try olApp := ComObjActive("Outlook.Application")
    catch
        throw Exception("Unable to connect to Outlook.")
    return olApp
}

Refresh() {
    LV_Delete()  ; Clear the listview
    for COMAddIn, in OutlookConnect().COMAddIns
        LV_Add(""
            , (COMAddIn.Connect = -1 ? "En" : "Dis") "abled"
            ,  COMAddIn.Description
            ,  COMAddIn.ProgId
            ,  COMAddIn.Guid)
    LV_ModifyCol()  ; Auto-size each column to fit its contents.
}

ToggleSelected() {
    static ColumnNumber := 3
    olApp := OutlookConnect()
    RowNumber := 0  ; This causes the first loop iteration to start the search at the top of the list.
    Loop {  ; Get each selected row in the listview
        RowNumber := LV_GetNext(RowNumber)  ; Resume the search at the row after that found by the previous iteration.
        if !RowNumber  ; The above returned zero, so there are no more selected rows.
            break
        if LV_GetText(ProgId, RowNumber, ColumnNumber) {
            COMAddIn := olApp.COMAddIns.Item[ProgId]
            COMAddIn.Connect := COMAddIn.Connect = -1 ? 0 : -1
        }
    }
    Refresh()
}


Re: Outlook COM - Enable or disable add-ins

Posted: 18 Nov 2016, 15:51
by Rami
Great !! You are so fast! :)
But, it enables the selected add-in but it doesn't disable it :)

Re: Outlook COM - Enable or disable add-ins

Posted: 18 Nov 2016, 16:03
by kon
There was a typo in my post above. Can you try it again?

Re: Outlook COM - Enable or disable add-ins

Posted: 18 Nov 2016, 17:08
by Rami
Oh man!
You saved me hours, even days of work!!
Thanks a lot Kon! Thank you!

you can mark your answer as the best answer :)

Re: Outlook COM - Enable or disable add-ins

Posted: 21 Nov 2016, 12:51
by Rami
Hi again :)
I think what I will ask for is a lot easier since we have a ready one, but i cannot figure it out by my self since i know nothing regarding COM and these stuff.
Is there a way to make it looks only for one add-in?

let's say (from your script)
Description: Maxhire
ProgId: MHOLAddin.clsOutlookInt

Is it possible to make the script looks ONLY for Maxhire, and disable it if it's enabled?
If it's already disabled then ExitApp

Thank you

Re: Outlook COM - Enable or disable add-ins

Posted: 21 Nov 2016, 16:36
by Rami
I mean, the script does its job by disabling Maxhire just by double click on it, but check at the beggining if Maxhire is disabled the script will exit

Re: Outlook COM - Enable or disable add-ins

Posted: 21 Nov 2016, 16:44
by kon

Code: Select all

COMAddIn := ComObjActive("Outlook.Application").COMAddIns.Item["MHOLAddin.clsOutlookInt"]
if (COMAddIn.Connect = -1)
    COMAddIn.Connect := 0

Re: Outlook COM - Enable or disable add-ins

Posted: 21 Nov 2016, 16:48
by Rami
Thanks Kon :superhappy:

:clap: :clap: :clap: :clap: