I tried the solutions in Launching Microsoft Edge with URL from code and How to open URL in Microsoft Edge from the command line? but they do not work for me.
Here's my code:
std::string url = "http://www.test.com";
std::wstring quotedArg = L"microsoft-edge:\"" + url + L"\"";
std::vector<WCHAR> argBuff(quotedArg.w_size() + 1);
wcscpy_s(&argBuff[0], argBuff.size(), quotedArg.w_str());
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
si.cb = sizeof si;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
if (!CreateProcess(L"start", &argBuff[0], NULL, NULL, FALSE,
0, NULL, NULL, &si, &pi)) {
DWORD error = GetLastError(); // here error = 2
return false;
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
The error code after CreateProcess()
is 2, which in https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx stands for ERROR_FILE_NOT_FOUND
.
Update 1:
To Dúthomhas's questions:
I'm not binding the user with Edge. I was using ShellExecuteEx()
to open http/https URL as below snippet.
SHELLEXECUTEINFO sei = { };
sei.cbSize = sizeof sei;
sei.nShow = SW_SHOWNORMAL;
sei.lpFile = url.w_str();
sei.lpVerb = L"open";
sei.fMask = SEE_MASK_CLASSNAME;
sei.lpClass = url.startsWith("https:")
? L"https"
: L"http";
if (ShellExecuteEx(&sei)) {
return true;
}
However this does not work for Microsoft Edge and will pop up error dialog saying
<URL> The specified module could not be found
.
Update 2:
Put the full path of cmd /C start
in CreateProcess()
as suggested by Dúthomhas make the call succeeds,
wui::string quotedArg = L"/C start microsoft-edge:" + url;
std::vector<WCHAR> argBuf(quotedArg.w_size() + 1);
wcscpy_s(&argBuf[0], argBuf.size(), quotedArg.w_str());
CreateProcess(L"C:\\Windows\\System32\\cmd.exe", &argBuf[0], NULL,
NULL, FALSE, 0, NULL, NULL, &si, &pi)
But the result is no browser opened and a pop up dialog showing
microsoft-edge:<UR> The specified module could not be found
.