![](/img/trans.png)
[英]Process.Start() open URL throws Win32Exception sometimes?
[英]Process.Start to open an URL, getting an Exception?
我正在嘗試按照在 google 甚至 MSDN 上編寫的簡單方法打開一個 URL。 但由於未知原因,我收到如下異常:
Win32Exception was unhandled
Message: Application not found
這是我的代碼:
private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
ProcessStartInfo sInfo = new ProcessStartInfo("http://github.com/tbergeron/todoTxt");
Process.Start(sInfo);
}
知道為什么它失敗了嗎?
非常感謝!
我在嘗試使用 .NET Core 時遇到了類似的問題並得到了Win32Exception
,我是這樣處理的:
var ps = new ProcessStartInfo("http://myurl")
{
UseShellExecute = true,
Verb = "open"
};
Process.Start(ps);
這顯然是特定於機器的行為( http://devtoolshed.com/content/launch-url-default-browser-using-c )。
鏈接的文章建議使用Process.Start("http://myurl")
但捕獲Win32Exception
並回退到Process.Start("IExplore.exe", "http://myurl")
:
try
{
Process.Start("http://myurl");
}
catch (Win32Exception)
{
Process.Start("IExplore.exe", "http://myurl");
}
可悲的是,在嘗試了幾乎所有東西之后,這是我在我的機器上能做的最好的事情。
您正在尋找Process.Start()
的string
重載:
Process.Start("http://github.com/tbergeron/todoTxt");
如果要在默認瀏覽器中啟動,請將 start 放在它前面:
new ProcessStartInfo("start http://github.com/tbergeron/todoTxt");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.