对于程序A.EXE
当用户第一次启动程序A.EXE的时候,启动成功
当用户再次启动A.EXE,由于已经启动了一个,就不能再启动第二个,这个如何控制啊?

解决方案 »

  1.   

    现在用C#使用private static Process RunningIntance()        {            Process currentProcess = Process.GetCurrentProcess();            Process[] processCollection = Process.GetProcessesByName(currentProcess.ProcessName);            foreach (Process p in processCollection)            {                if (p.Id != currentProcess.Id)  //检查ID是否相同                {                    //检查运行文件路径是否相同                    if (System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == currentProcess.MainModule.FileName)                        return currentProcess;                }            }            return null;        }可判断进程是否运行,并得到该进程。
      

  2.   

    参考:http://www.codeproject.com/csharp/singleinstance.asp
      

  3.   

    或者:http://www.west263.com/www/info/41170-1.htm
      

  4.   

    static void Main()
    {
    bool bExist;
    System.Threading.Mutex MyMutex=new System.Threading.Mutex(true,"OnlyOneTime",out bExist);
    if(bExist)
    {
    Application.Run(new WinForm());
    MyMutex.ReleaseMutex();
    }
    else
    {
    MessageBox.Show("程序已经运行!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }
    }