c# 获取默认浏览器的路径
时间: 2023-10-07 15:14:21 浏览: 58
你可以使用 `Registry` 类来获取默认浏览器的路径。下面是一个示例代码:
```csharp
using Microsoft.Win32;
public static string GetDefaultBrowserPath()
{
string browserPath = string.Empty;
// 获取HKEY_CLASSES_ROOT\HTTP\shell\open\command键的值
using (RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command"))
{
if (key != null)
{
// 获取注册表中的默认浏览器路径
string command = key.GetValue(null) as string;
if (!string.IsNullOrEmpty(command))
{
// 提取浏览器路径
int index = command.IndexOf(".exe", StringComparison.OrdinalIgnoreCase);
if (index >= 0)
{
browserPath = command.Substring(0, index + 4);
}
}
}
}
return browserPath;
}
```
你可以调用 `GetDefaultBrowserPath` 方法来获取默认浏览器的路径。请注意,这种方法只适用于 Windows 操作系统。