问题
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