检查exe文件或bat文件是否正在运行C# [英] Check if a exe or bat files is running C#

查看:223
本文介绍了检查exe文件或bat文件是否正在运行C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助!如何检测我的bat文件是否被点击或运行并显示MessageBox。



我在destop文件上获得了Run.exe,我想显示其他MessageBox和我的bat文件也在destop,我想显示其他MessageBox。



Hi i need help! How can i Detect if my bat files is clicked or running and show MessageBox.

I got Run.exe on destop file which i want to show other MessageBox and my bat files also at destop which i want to show other MessageBox.

using System.Diagnostics;

Process proc = new Process();
proc.StartInfo.FileName = "/Users/Po/Desktop/Testing.bat";
if (proc.Start())
 {
 MessageBox.Show("This is bat files Open!.");
 }
else
 {
 MessageBox.Show("Welcome");
 }







Testing.bat文件文件




Testing.bat Files Text

"C:\Users\Po\Visual Studio 2010\Projects\PoTest\PoTest\bin\Debug\Run.exe"  -C





我在Destop上的Run.exe



My Run.exe on Destop

Start in:"C:\Users\Po\Visual Studio 2010\Projects\PoTest\PoTest\bin\Debug\Run.exe"

推荐答案

请参阅我的评论问题。



在批处理文件中,应用程序启动时有一个本质区别,-C命令行参数。使用它:

http ://msdn.microsoft.com/en-us/library/system.environment.commandline%28v=vs.110%29.aspx [ ^ ],

< a href =http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs%28v=vs.110%29.aspx> http://msdn.microsoft.com/en-us /library/system.environment.getcommandlineargs%28v=vs.110%29.aspx [ ^ ],

另一种方法是使用入口点方法参数: http://msdn.microsoft.com/en-us/library/acy3edy3%28v = vs.110%29.aspx [ ^ ]。



如果你解释了你的目标, /或如果这不合适,我会给你另一个解决方案,我几乎可以肯定找出你的父进程是不需要的。



-SA
Please see my comment to the question.

In your batch file, the application is started with one essential difference, "-C" command-line parameter. Use it:
http://msdn.microsoft.com/en-us/library/system.environment.commandline%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs%28v=vs.110%29.aspx[^],
another way is using entry-point method parameters: http://msdn.microsoft.com/en-us/library/acy3edy3%28v=vs.110%29.aspx[^].

If you explain your goal, and/or if this is not suitable, I'll give you another solution, and I'm almost sure that finding out what was your parent process would not be needed.

—SA


嗨谢谢!你的链接真的很有帮助!

对不起,我还没弄清楚系统是如何运行的!

毕竟我找到了链接上的解决方案!

谢谢!
Hi Sergey! Your Link really helpful!
Sorry i did not get clear how the systems running!
After all i figure out the solution on the link!
Thanks!


这篇关于检查exe文件或bat文件是否正在运行C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆