如何将 Win32 GUI 应用程序作为后台进程启动?

How to start a Win32 GUI application as a background process?

当 COM 使用从 ProgId 派生的 CLSID(例如“Excel.Application”)通过 CoCreateInstance() 启动进程外服务器时,这究竟是如何发生的?

我可以在注册表中看到提供命令行的条目:

当 COM 启动新的 Excel 服务器时(如果还没有 运行),excel.exe 进程在后台(任务管理器 window),UI 无法访问。我想复制这个。

我试过这个简单的代码:

#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);
}

但在前台弹出 Excel。

COM 正在调用什么 Win32 API 以在后台启动 Excel?

Command-line switches for Microsoft Office products

/e/embed

防止出现 Excel 启动屏幕和打开新的空白工作簿。

例子

excel.exe /e