在 Windows 10 上尝试获取默认 Web 浏览器路径失败 [英] Trying to get default web browser path fails on Windows 10

查看:29
本文介绍了在 Windows 10 上尝试获取默认 Web 浏览器路径失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用安装程序中执行以下操作(请注意,此项目的安装程序只是一个 Windows 可执行文件 (setup.exe) 而不是 MSI.)

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.)

首先我需要检查 .htm.html 文件类型是否存在文件关联.我已经这样做了.然后,如果没有关联,我需要添加它们以通过网络浏览器打开.

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?

所以我是这样做的:

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

这似乎有效,除非我在 Windows 10 上运行它时我得到这个路径(当默认为 Edge 浏览器时):

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

C:\WINDOWS\system32\LaunchWinApp.exe

那么我如何重置参数以启动它?

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

推荐答案

尝试使用 ASSOCSTR_COMMAND 而不是 ASSOCSTR_EXECUTABLE.通过使用ASSOCSTR_EXECUTABLE,您要求只是 可执行文件本身,这正是您要返回的内容.ASSOCSTR_COMMAND 应该为您提供可执行文件的整个命令行.

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.

这篇关于在 Windows 10 上尝试获取默认 Web 浏览器路径失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆