惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
SecWiki News
SecWiki News
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
量子位
M
MIT News - Artificial intelligence
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
TaoSecurity Blog
TaoSecurity Blog
博客园 - 【当耐特】
H
Heimdal Security Blog
腾讯CDC
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
S
Schneier on Security
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Cybersecurity and Infrastructure Security Agency CISA
S
SegmentFault 最新的问题
大猫的无限游戏
大猫的无限游戏
Application and Cybersecurity Blog
Application and Cybersecurity Blog
F
Full Disclosure
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Threatpost
月光博客
月光博客
A
Arctic Wolf
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
T
Troy Hunt's Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
D
DataBreaches.Net
O
OpenAI News
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
小众软件
小众软件
V
Vulnerabilities – Threatpost
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
T
The Exploit Database - CXSecurity.com
Martin Fowler
Martin Fowler
美团技术团队
P
Privacy International News Feed

博客园 - Findekano

C#异步调用的bug? 恩,VS调试时候的监视也不能够尽信啊 最近正在看的几本书 VS.NET2005使用体验(二) [C# FAQ]通过Windows Forms预处理Win32消息 将应用程序直接加入到"Run..."中打开的小工具 VS.NET2005使用体验(一) OpenGL & MFC 相关联接 .::Findekano's Tidbet:: .::Findekano's Tidbet:: .::Findekano's Tidbet:: .:: Findekano's Tidbet :: CorelDraw's Application Recovery Manager.. .:: Findekano's Tidbet :: C#&.NET Framework中的Beep .:: Findekano's Tidbet :: 今天开始,努力攒钱... 又闻到味道 如何保持代码格式?
[C# FAQ]C#代码中如何启动另一个应用程序或批处理程序?
Findekano · 2004-06-05 · via 博客园 - Findekano

original URL: How can I run another application or batch file from my Visual C# .NET code?
Posted by: Duncan Mackenzie, MSDN
This post applies to Visual C# .NET 2002/2003


如果你要运行一个命令行程序,或者打开一个windows应用程序,或者打开默认的web浏览器或email客户端,..你应该如何在你的C#代码中实现这个功能呢?
以下这些例子完成相同的任务,你可以使用System.Diagnostics.Process中的类和方法完成这些任务,甚至作的更多。
例1:不管输出结果,仅仅是运行一个命令行程序:

private void simpleRun_Click(object sender, System.EventArgs e){
 System.Diagnostics.Process.Start(@"C:\listfiles.bat");
}

例2. 得到程序运行结果等待直到程序中止(同步运行程序)private void runSyncAndGetResults_Click(object sender, System.EventArgs e){
 System.Diagnostics.ProcessStartInfo psi =
  
new System.Diagnostics.ProcessStartInfo(@"C:\listfiles.bat");
 psi.RedirectStandardOutput =
true;
 psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
 psi.UseShellExecute =
false;
 System.Diagnostics.Process listFiles;
 listFiles = System.Diagnostics.Process.Start(psi);
 System.IO.StreamReader myOutput = listFiles.StandardOutput;
 listFiles.WaitForExit(2000);
 
if (listFiles.HasExited)
 {
  
string output = myOutput.ReadToEnd();
  
this.processResults.Text = output;
 }
}

 例3. 使用用户机器里的默认浏览器显示URL
private void launchURL_Click(object sender, System.EventArgs e){
 
string targetURL = @http://www.duncanmackenzie.net;
 System.Diagnostics.Process.Start(targetURL);
}

我的看法是,同样是打开浏览器显示URL,使用例3种的方法比启动IE并以URL作为参数要来得合理。
例3的代码将会启动用户的默认浏览器,而并不总是IE。这样你更有可能给用户带来他们所希望得到的体验,
并且可以利用具有最新连接信息的浏览器。