0

I need to launch the default browser on windows with c++ code.

I have found this way: use the api "AssocQueryString" to find the app which could open the file with an extend file name "html". It work well when the default browser is ie or chrome or .., but if the default browser is an UWP app such as "Microsoft Edge", I only get ""C:\Windows\system32\LaunchWinApp.exe"

DWORD size = MAX_PATH;
char buff[MAX_PATH];

int err = AssocQueryStringA(ASSOCF_INIT_IGNOREUNKNOWN, ASSOCSTR_EXECUTABLE ".html", NULL, buff, &size);

So , is there a way to launch the default UWP browser?

I have tried this

SHELLEXECUTEINFOW sei = { sizeof sei };
sei.lpVerb = L"open";
sei.lpFile = L"microsoft-edge:";
ShellExecuteExW(&sei);

But I can only run the code when I have known that the default browser is Edge, and if the default browser is an another UWP application, how to find the name to pass to the lpFile?

So, is there a way to launch the default browser without openning a specified url?

jinchx
  • 31
  • 4
  • When calling `AssocQueryString()` on Win8+, have you tried using the `ASSOCF_IS_PROTOCOL` flag and set the `pszAssoc` to `"http"`? And maybe try using `ASSOCSTR_COMMAND` instead of `ASSOCSTR_EXECUTABLE` to get the full command line needed to execute the app. – Remy Lebeau Nov 16 '18 at 03:17
  • Thanks but it doesn't help when it comes to UWP – jinchx Nov 16 '18 at 05:46
  • I have found that it helps: [https://stackoverflow.com/questions/43376033/how-do-i-open-default-browser-to-home-page-in-c][how-do-i-open-default-browser-to-home-page-in-c] – jinchx Nov 16 '18 at 06:19
  • well, I have found a problem when launching Edge, and I haven't found a solution. The problem is if call "ShellExecute(nullptr, L"open", szPath, (L"shell:AppsFolder\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge" , nullptr, SW_SHOWNORMAL) " too frequently, an error will occur – jinchx Nov 26 '18 at 03:45

0 Answers0