用程式呼叫瀏覽器打開某個網頁
當然網頁可以換成其他 URL 或本地檔案。
string target= "http://tw.yahoo.com";
try
{
System.Diagnostics.Process.Start(target);
}
catch(System.ComponentModel.Win32Exception noBrowser)
{
if (noBrowser.ErrorCode==-2147467259)
MessageBox.Show("瀏覽器錯誤:"+noBrowser.Message);
}
catch (System.Exception other)
{
MessageBox.Show("錯誤訊息:"+other.Message);
}
修改一下,變成以下的內容:
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = @"C:\Program Files\Internet Explorer\Iexplore.exe";
myProcess.StartInfo.Arguments = "http://tw.yahoo.com";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
連線網路磁碟機:(還沒測成功)
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = @"C:\Windows\System32\net.exe";
myProcess.StartInfo.Arguments = "use \My_Server pwd /user:Username";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
0 Comments on “用程式呼叫瀏覽器打開某個網頁”