Home > Software engineering >  How to start a Win32 GUI application as a background process?
How to start a Win32 GUI application as a background process?

Time:09-18

When COM starts an out-of-process server via CoCreateInstance() with a CLSID derived from ProgId (eg "Excel.Application"), how exactly does this happen?

I can see entries in the Registry which give the command line: enter image description here

When COM starts a new Excel server (if one is not already running), the excel.exe process is in the background (the lower part of the Task Manager window), and not accessible to the UI. I would like to replicate this.

I have tried this simple code:

#include <iostream>
#include <windows.h>

using namespace std;
int main()
{
    string strApp{"C:\\Program Files\\Microsoft Office\\root\\Office16\\EXCEL.EXE"};
    string strParams{"/automation /x"};

    HINSTANCE hs = ShellExecuteA(NULL, "open", strApp.c_str(), strParams.c_str(), NULL, SW_HIDE);
}

but up pops Excel in the foreground.

What Win32 API calls is COM making to start Excel in the background?

CodePudding user response:

Command-line switches for Microsoft Office products

/e or /embed

Prevents the Excel startup screen from appearing and a new blank workbook from opening.

Example

excel.exe /e

  • Related