Can’t get all excel processes to stop when closing through Powershell

For general guidance on how to release (Excel) COM objects, see the bottom section. $excel.Quit() is enough to eventually terminate the Excel process, but when that happens depends on when the garbage collector happens to run the next time. Your attempt to explicitly release Excel with [System.Runtime.InteropServices.Marshal]::ReleaseComObject($excel) is insufficient, because variables $script:workbook and $script:ws1 still … Read more

Exposing Property as Variant in .NET for Interop

COM Automation supports a default property, the property that has dispid 0. This is used in VB6 code to great effect, generating really compact code. A typical example is: rs!Customer = “foo” Which is syntax sugar for: rs.Fields.Item(“Customer”).Value = “foo” Three default properties being used here without being named in the original statement. The Recordset … Read more

What are the differences between using the New keyword and calling CreateObject in Excel VBA?

As long as the variable is not typed as object Dim xmlDocument as MSXML2.DOMDocument Set xmlDocument = CreateObject(“MSXML2.DOMDocument”) is the same as Dim xmlDocument as MSXML2.DOMDocument Set xmlDocument = New MSXML2.DOMDocument both use early binding. Whereas Dim xmlDocument as Object Set xmlDocument = CreateObject(“MSXML2.DOMDocument”) uses late binding. See MSDN here. When you’re creating externally provided … Read more

What options are available for Shell32.Folder.GetDetailsOf(..,..)?

I figured this out by accident. If you pass null into GetDetailsOf then it responds with the column names. For example, execute the following JScript with cscript: var shellapp = WScript.CreateObject(“Shell.Application”); var folder = shellapp.NameSpace(“D:\\”); for (var j = 0; j < 0xFFFF; j++) { detail = folder.GetDetailsOf(null, j); if (!detail) { break; } WScript.Echo(“[” … Read more

Hosting the .NET runtime in a Delphi Program

In the Jedi Code Library (JCL) – free – there is a JclDotNet.pas, containing a class TJclClrHost, probably doing what you want: TJclClrHost = class(TJclClrBase, ICorRuntimeHost) private FDefaultInterface: ICorRuntimeHost; FAppDomains: TObjectList; procedure EnumAppDomains; function GetAppDomain(const Idx: Integer): TJclClrAppDomain; function GetAppDomainCount: Integer; function GetDefaultAppDomain: IJclClrAppDomain; function GetCurrentAppDomain: IJclClrAppDomain; protected function AddAppDomain(const AppDomain: TJclClrAppDomain): Integer; function RemoveAppDomain(const … Read more

What can you do with COM/ActiveX in Python? [closed]

First you have to install the wonderful pywin32 module. It provides COM support. You need to run the makepy utility. It is located at C:\…\Python26\Lib\site-packages\win32com\client. On Vista, it must be ran with admin rights. This utility will show all available COM objects. You can find yours and it will generate a python wrapper for this … Read more

Use Office Interop on ASP.net MVC6 website

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment. If you are building a solution that runs in a server-side … Read more

As of today, what is the right way to work with COM objects? [duplicate]

The .NET / COM interop is well designed, and works correctly. In particular, the .NET Garbage Collector correctly tracks COM references, and will correctly release COM objects when they have no remaining runtime references. Interfering with the reference counts of COM object by calling Marshal.ReleaseComObject(…) or Marshal.FinalReleaseComObject(…) is a dangerous but common anti-pattern. Unfortunately, some … Read more