Trying to get default web browser path fails on Windows 10

喜你入骨 提交于 2019-12-11 16:16:53

问题


I'm doing the following in my app's installer (note that the installer for this project is just a Windows executable (setup.exe) and not an MSI.)

First I needed to check if there're file associations for .htm and .html file types. I did so already. And then if there's no association I needed to add them to be opened by a web browser.

To make a lesser of an impact on a user's system, I thought to go with the user's default web browser. The question is how to find its path?

So I was doing this:

//Get default web browser path
WCHAR wbuffPath[MAX_PATH] = {0};
DWORD dwszBuffPath = MAX_PATH;
::AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, L"http", L"open", wbuffPath, &dwszBuffPath);

which seems to work, except when I run it on Windows 10 I get this path (when default is the Edge browser):

C:\WINDOWS\system32\LaunchWinApp.exe

So how do I get the reset of the parameters to start it?


回答1:


Try using ASSOCSTR_COMMAND instead of ASSOCSTR_EXECUTABLE. By using ASSOCSTR_EXECUTABLE, you are asking for just the executable by itself, which is exactly what you are getting back. ASSOCSTR_COMMAND should give you the whole command line for the executable.



来源:https://stackoverflow.com/questions/35258970/trying-to-get-default-web-browser-path-fails-on-windows-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!