none
Powershell access to AddIn RRS feed

  • Question

  • Hi All,

    Sorry if this is the wrong forum (if so, please redirect me).

    I've written a Word 2010 Addin in C# which is working just fine.  Now trying to do some test automation utilizing PowerShell.

    But I can't seem to access any of my AddIn classes/objects/properties/methods.  I know my AddIn is a ComAddIn and I'm suspecting that the call semantics is my problem.  Any assistance would be greatly appreciated.

    Thanks, Billwa992

    Tuesday, July 19, 2011 2:06 AM

Answers

  • Hi Cindy,

    Thanks for the pointers, they only helped by pointing me to the links below that were the key.

    Calling Code in Application-Level Add-ins from Other Office Solutions

    and

    Walkthrough: Calling Code in an Application-Level Add-in from VBA

    After adding the AddInUtilities.cs to my AddIn project per the second link (modified appropriately to work in my WORD 2010 project - I simply have ImportData returning a public static string from the ThisAddIn Class) I created the following PowerShell Script:

    # Word Application Object needs to be made
    $word = New-Object -com Word.Application
    $word.Visible = $true # Sets the Microsoft Word Window to be visable, set true for debugging

    $file = "c:\<path>\Rule1Test.docx"
    $doc = $word.Documents.Open($file)
    "Opened $($doc.fullname)."
       
    $myaddin = $word.COMAddIns.Item("<insert addin name here>")
    "My AddIn $($myaddin.ProgId) is Connected"

    $automationObject = $myaddin.Object   
    $mystring = $automationObject.ImportData()
    "My AddIn string is $($mystring)."

    I hope this helps the next person attempting this.

    Thanks, Billwa992


    • Marked as answer by billwa992 Tuesday, July 19, 2011 6:33 PM
    Tuesday, July 19, 2011 6:33 PM

All replies

  • Hi Bill

    You're getting a bit beyond my area of immediate expertise, and I don't know anything about PowerShell (as in, is it managed code, COM code...?), BUT

    If this is a VSTO add-in then the VSTO runtime is loading it in its own AppDomain; if it's a Shared Add-in mscoree.dll is loading it in a "shared" AppDomain with other add-ins and such.

    In either case, anything running in an AppDomain is "shielded" to the outside. A couple of years ago, the advice was to use Remoting to access such a process. Apparently, these days there's something new/different, although Remoting will still work. But in any case, I imagine the issue is getting access to the process within its domain...

    Not sure whether this will help you any further, as I can't provide more detail than that?


    Cindy Meister, VSTO/Word MVP
    Tuesday, July 19, 2011 11:26 AM
    Moderator
  • Thanks for the quick response, Cindy.

    is there a PowerShell forum??  Or other venue to ask this question.  Can't believe I'm the only one having this problem.

    I'm new to Powershell too, but it is Object oriented and can access COM objects (as least that's my understanding), WMI, .NET, as well as traditional Console level of functionality.  I have no problems accessing objects in the Microsoft.Office.Interop.Word namespace within Word (I can turn Track Changes on, change font to Bold, etc..). 

    My AddIn uses VSTO, for an Application Level AddIn with my customized Ribbon using XML approach.

    Can you direct me to information about your remoting suggestion (as powershell has support to remoting to other machines for system admin purposes).  Not sure your "remoting" is referencing Powershell remoting.

    Thanks, Billwa992

    Tuesday, July 19, 2011 4:17 PM
  • Hi Bill

    Well, I find a PowerShell forum (picked up from a search on MSDN) here:
    http://forums.iis.net/1151.aspx

    Remoting: See if this discussion helps
    http://social.msdn.microsoft.com/forums/en-us/vsto/thread/98657A23-B147-4144-B051-83905CE5718B


    Cindy Meister, VSTO/Word MVP
    Tuesday, July 19, 2011 4:36 PM
    Moderator
  • Hi Cindy,

    Thanks for the pointers, they only helped by pointing me to the links below that were the key.

    Calling Code in Application-Level Add-ins from Other Office Solutions

    and

    Walkthrough: Calling Code in an Application-Level Add-in from VBA

    After adding the AddInUtilities.cs to my AddIn project per the second link (modified appropriately to work in my WORD 2010 project - I simply have ImportData returning a public static string from the ThisAddIn Class) I created the following PowerShell Script:

    # Word Application Object needs to be made
    $word = New-Object -com Word.Application
    $word.Visible = $true # Sets the Microsoft Word Window to be visable, set true for debugging

    $file = "c:\<path>\Rule1Test.docx"
    $doc = $word.Documents.Open($file)
    "Opened $($doc.fullname)."
       
    $myaddin = $word.COMAddIns.Item("<insert addin name here>")
    "My AddIn $($myaddin.ProgId) is Connected"

    $automationObject = $myaddin.Object   
    $mystring = $automationObject.ImportData()
    "My AddIn string is $($mystring)."

    I hope this helps the next person attempting this.

    Thanks, Billwa992


    • Marked as answer by billwa992 Tuesday, July 19, 2011 6:33 PM
    Tuesday, July 19, 2011 6:33 PM