日期:2014-05-17 浏览次数:20989 次
/// <summary>
/// 启动进程的程序路径
/// </summary>
private string m_fileName = "Notepad.exe";
void ProcessAdd(EventArgs e)
{
string path = Environment.CurrentDirectory + "\\MyFile";
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
string argument = System.IO.Path.Combine(path, Guid.NewGuid().ToString() + ".txt");
if (!System.IO.File.Exists(argument))
{
System.IO.File.CreateText(argument);
}
//设置要启动的就用程序及参数
ProcessStartInfo ps = new ProcessStartInfo(m_fileName, argument);
ps.WindowStyle = ProcessWindowStyle.Normal;
Process p = new Process();
p.StartInfo = ps;
p.Start();
//等待启动完成,否则获取进程信息可能失败
p.WaitForInputIdle();
//MessageBox.Show(Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(this.m_fileName)).Length.ToString());
//创建新的Process组件的数组,并将它们与指定的进程名称(Notepad)的所有进程资源相关联.
Process[] myprocesses;
var fileName = System.IO.Path.GetFileNameWithoutExtension(m_fileName);
myprocesses = Process.GetProcessesByName(fileName);
foreach (Process p1 in myprocesses)
{
//通过向进程主窗口发送关闭消息达到关闭进程的目的
p1.CloseMainWindow();
&n