win10系统中启动Edge浏览器带命令行参数:
start microsoft-edge:
#include <Windows.h>#include <shellapi.h>int main(){SHELLEXECUTEINFO sf = { 0 };sf.cbSize = sizeof(SHELLEXECUTEINFO);sf.lpFile = "microsoft-edge:/";sf.nShow = 1;__debugbreak();// 断点ShellExecuteEx(&sf); // 跟踪调试执行过程return 0;}
命令行编译: cl shell.cpp /link shell32.lib
COM接口启动方式:
#include "windows.h"#include <atlbase.h>#include <atlstr.h>#include <Shobjidl.h>#include "Shellapi.h"int main(){HRESULT hr = E_FAIL;hr = CoInitialize(NULL);CComPtr<IApplicationActivationManager> activationManager;LPCWSTR edgeAUMID = L"Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge";//LPCWSTR edgeAUMID = L"Microsoft.Windows.Spartan_cw5n1h2txyewy!Microsoft.Spartan.Spartan";hr = CoCreateInstance(CLSID_ApplicationActivationManager, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&activationManager));if (SUCCEEDED(hr)){DWORD newProcessId;__debugbreak();hr = activationManager->ActivateApplication(edgeAUMID, L"", AO_NONE, &newProcessId);}else{wprintf(L"Failed to launch Microsoft Edge");}return 0;}