c#启动和结束外部进程
来源:互联网 发布:linux 查看cpu主频 编辑:程序博客网 时间:2024/05/22 05:01
启动外部进程:
public bool StartProc(string Path, string ProcName)
{
bool result = false;
System.Collections.ArrayList procList = new System.Collections.ArrayList();
string tempName = "";
Process[] temp = Process.GetProcessesByName(ProcName);//在所有已启动的进程中查找需要的进程;
if (temp.Length > 0)//如果查找到
{
IntPtr handle = temp[0].MainWindowHandle;
SwitchToThisWindow(handle, true); // 激活,显示在最前
}
else
{
Process.Start(Path + ProcName + ".exe");//否则启动进程
}
foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
{
tempName = thisProc.ProcessName;
procList.Add(tempName);
if (tempName == ProcName)
{
result = true;
}
}
return result;
}
[DllImport("user32.dll")]
public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
public bool closeProc(string ProcName)
{
bool result = false;
System.Collections.ArrayList procList = new System.Collections.ArrayList();
string tempName = "";
foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
{
tempName = thisProc.ProcessName;
procList.Add(tempName);
if (tempName == ProcName)
{
if (!File.Exists(PublicValue.ExePath + "\\" + ProcName + ".bat"))
{
FileInfo myfile = new FileInfo(PublicValue.ExePath + "\\" + ProcName + ".bat");
FileStream fs = myfile.Create();
fs.Close();
StreamWriter sw = File.AppendText(PublicValue.ExePath + "\\" + ProcName + ".bat");
sw.WriteLine("@echo off");
sw.WriteLine("taskkill /f /t /im " + ProcName + ".exe\n");
sw.WriteLine("echo.&echo.");
sw.WriteLine("del " + PublicValue.ExePath + "\\" + ProcName + ".bat");
sw.Flush();
sw.Close();
}
Process.Start(PublicValue.ExePath + "\\" + ProcName + ".bat");
result = true;
}
}
return result;
}
PublicValue.ExePath = System.Windows.Forms.Application.StartupPath;
- c#启动和结束外部进程
- C# 启动和结束进程
- 启动和结束进程
- C#启动外部exe进程
- C#启动和关闭外部进程的方法
- 启动和等待进程结束
- 启动和等待进程结束
- win32 启动和结束进程
- IronPython调用C#启动外部进程
- VC获取进程启动和结束时间
- VC获取进程启动和结束时间
- VC获取进程启动和结束时间
- Erlang 督程 启动和结束子进程
- 在VC中如何结束进程和启动新进程?
- 在VC中如何结束进程和启动新进程?
- 在VC中如何结束进程和启动新进程?
- 在VC中如何结束进程和启动新进程
- 在VC中如何结束进程和启动新进程?
- hdu 5952 Counting Cliques
- new String 和toString得区别
- Linux 查找文件或命令
- Java--IO流之字节流介绍--InputStream和OutputStream
- 快速幂讲解
- c#启动和结束外部进程
- javaEE之Listener
- 王者荣耀提取攻略
- java的历程
- 【HDU 6000 Wash】优先队列 & 贪心
- linux命令-sed命令使用(3)
- (转)Android——高德地图设置中心点和缩放比例,获取两点之间距离
- poj1681 Painter's Problem(gauss+dfs判定)
- Java获取此次请求URL以及服务器根路径的方法