使用进程名禁止程序运行多次

string moduleName = Process.GetCurrentProcess().MainModule.ModuleName;
string prcessName = System.IO.Path.GetFileNameWithoutExtension(moduleName);
Process[] processes = Process.GetProcessesByName(prcessName);
if (processes.Length>1)
{
    MessageBox.Show("程序已经运行!");
    Process.GetCurrentProcess().Kill();
}
posted @ 2015-05-30 23:59  -H&H-  阅读(188)  评论(0)    收藏  举报