参考:
参考:
参考:
参考代码:
//=====判断进程法:(修改程序名字后依然能执行)===== Process current = Process.GetCurrentProcess(); Process[] processes = Process.GetProcessesByName(current.ProcessName); foreach (Process process in processes) { if (process.Id != current.Id) { if (process.MainModule.FileName == current.MainModule.FileName) { MessageBox.Show("程序已经运行!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } }
注意:代码复制到 Program.cs 文件的 Main 函数里面,如下图所示!
参考:
Process[] temp = Process.GetProcessesByName("WindowsFormsApplication2");if (temp.Length > 0) MessageBox.Show("dfkdkl");else Process.Start(@"C:\Program Files (x86)\默认公司名称\Setup1\WindowsFormsApplication2.exe");
参考: