【发布时间】:2016-10-11 01:31:40
【问题描述】:
我目前有以下代码通过 WPF 应用程序的数据网格内的按钮启动:
private static string GetStandardBrowserPath()
{
string browserPath = string.Empty;
RegistryKey browserKey = null;
try
{
//Read default browser path from Win XP registry key
browserKey = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command", false);
//If browser path wasn't found, try Win Vista (and newer) registry key
if (browserKey == null)
{
browserKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http", false); ;
}
//If browser path was found, clean it
if (browserKey != null)
{
//Remove quotation marks
browserPath = (browserKey.GetValue(null) as string).ToLower().Replace("\"", "");
//Cut off optional parameters
if (!browserPath.EndsWith("exe"))
{
browserPath = browserPath.Substring(0, browserPath.LastIndexOf(".exe") + 4);
}
//Close registry key
browserKey.Close();
}
}
catch
{
//Return empty string, if no path was found
return string.Empty;
}
//Return default browsers path
return browserPath;
}
这样返回浏览器路径如下:
"c:\\program files\\mozilla firefox\\firefox.exe -osint -url %1"
我想要做的是在 .exe 的末尾添加另一个命令行以强制浏览器以私有模式打开,最终用户知道这会发生,但我不确定如何执行此操作。我想使用的浏览器是:
- 谷歌浏览器
- 火狐
- 歌剧
- 互联网探索
例如
"c:\\program files\\mozilla firefox\\firefox.exe -private -osint -url %1"
或
"c:\\program files (x86)\\google\\chrome\\application\\chrome.exe -incognito -- %1"
【问题讨论】:
-
My browser 没有隐私浏览模式。
-
@Dr.Stitch 不是重复的,因为另一个问题是关于从网站打开私人模式,而这个问题是从本地桌面应用程序启动新浏览器。