0

We have a task which starts a PowerShell script that uses Excel Interop to extract regularly some graphs from Excel. But since updating from Win10_2004 to Win10_20H2 the following error occurs:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070520 A specified logon session does not exist. It may already have been terminated.

Part of the PowerShell-script to start Excel:

    $excelApp = New-Object -ComObject Excel.Application -Property @{DisplayAlerts = $false}

After updating to Win10_21H1 the problem still exists. Office 2016 is used with a local licensekey.

Steps already taken:

1. DCOMCNFG.exe

Go to:

    Component Service -> Computers -> My Computer -> DCOM Config -> Office Licensing COM Server 16 -> Properties -> Security -> Launch and Activation Permission

Select Customize and click on edit and add the user that runs the Application with full access

2. RegEdit.exe

Go to registry location:

    Computer\HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Common\Identity

and add registry key

    EnableADAL REG_DWORD 0x00000000 (0)

3. Desktop map

Create the following 2 maps:

    %windir%\System32\config\systemprofile\Desktop
    %windir%\SysWOW64\config\systemprofile\Desktop

4. Copy EXCEL.EXE to EXCEL_COPY.EXE

Go to map C:\Program Files (x86)\Microsoft Office\Root\Office16
and copy EXCEL.EXE to EXCEL_COPY.EXE

Change registry key

    Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WOW6432Node\CLSID\{00024500-0000-0000-C000-000000000046}\LocalServer32

from:

    C:\Program Files (x86)\Microsoft Office\Root\Office16\EXCEL.EXE /automation

to:

    C:\Program Files (x86)\Microsoft Office\Root\Office16\EXCEL_COPY.EXE /automation

Now everything works fine and Excel starts in an unattended task.

In this situation, after every update from Excel we have to make a manual copy to EXCEL_COPY.EXE. Which setting should we adjust so that the above copy action is no longer necessary?

hdeheer28
  • 1
  • 1
  • Does it help to do an [Office Repair](https://support.microsoft.com/en-us/office/repair-an-office-application-7821d4b6-7c1d-4205-aa0e-a6b40c5bb88b)? – Theo May 20 '21 at 12:31
  • 1
    I'm a little surprised that it was working at all. If I remember right, running Excel in a non-interactive session is unsupported. Since, using the Office automation COM objects opens Excel, that means it's also not supported in a non-interactive session. There are [workarounds](https://stackoverflow.com/q/4234615/696808), which is what I assume you were doing, but IMX they're quite fragile unless you keep an interactive session running and set the task to run when logged in. – Bacon Bits May 20 '21 at 14:11
  • 1
    If it *must* be non-interactive, then I'd investigate if the [ImportExcel Powershell module](https://www.powershellgallery.com/packages/importexcel) can do what you need. That does not require Excel at all, which might be nice because then you may not need to consume an Office license, either. – Bacon Bits May 20 '21 at 14:17
  • It has to work non-interactively because it runs on multiple servers and when one of them reboots, someone has to log in to create an interactive session. That goes wrong when nobody observes the restart. And we use Excel because it opens a worksheet with autorefreshed tables displayed in charts. The script extracts these charts to .png files to present on unmanaged screens. So because of the charts we think Excel is the only option. At this point, the solution is working perfectly. But it is not very robust. – hdeheer28 May 20 '21 at 17:00

0 Answers0