只禁止多个进程运行
来源:互联网 发布:淘宝手机详情图片尺寸 编辑:程序博客网 时间:2024/05/04 19:46
方法一:只禁止多个进程运行
方法二:禁止多个进程运行,并当重复运行时激活以前的进程
[STAThread]public static void Main(){ bool ret; System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out ret); if (ret) { System.Windows.Forms.Application.EnableVisualStyles(); //这两行实现 XP 可视风格 System.Windows.Forms.Application.DoEvents(); System.Windows.Forms.Application.Run(new Main()); // Main 为你程序的主窗体,如果是控制台程序不用这句 mutex.ReleaseMutex(); } else { MessageBox.Show(null, "有一个和本程序相同的应用程序已经在运行,请不要同时运行多个本程序。/n/n这个程序即将退出。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); // 提示信息,可以删除。 Application.Exit();//退出程序 }}
方法二:禁止多个进程运行,并当重复运行时激活以前的进程
[STAThread]public static void Main(){ //Get the running instance. Process instance = RunningInstance(); if (instance == null) { System.Windows.Forms.Application.EnableVisualStyles(); //这两行实现 XP 可视风格 System.Windows.Forms.Application.DoEvents(); //There isn't another instance, show our form. Application.Run(new Main()); } else { //There is another instance of this process. HandleRunningInstance(instance); }}public static Process RunningInstance(){ Process current = Process.GetCurrentProcess(); Process[] processes = Process.GetProcessesByName(current.ProcessName); //Loop through the running processes in with the same name foreach (Process process in processes) { //Ignore the current process if (process.Id != current.Id) { //Make sure that the process is running from the exe file. if (Assembly.GetExecutingAssembly().Location.Replace("/", "//") == current.MainModule.FileName) { //Return the other process instance. return process; } } } //No other instance was found, return null. return null;}public static void HandleRunningInstance(Process instance){ //Make sure the window is not minimized or maximized ShowWindowAsync(instance.MainWindowHandle, WS_SHOWNORMAL); //Set the real intance to foreground window SetForegroundWindow(instance.MainWindowHandle);}[DllImport("User32.dll")]private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);[DllImport("User32.dll")]private static extern bool SetForegroundWindow(IntPtr hWnd);private const int WS_SHOWNORMAL = 1;
- 只禁止多个进程运行
- 禁止多个进程运行
- 禁止运行程序多个实例
- VC 程序只运行一个进程,再次运行传参数给第一个进程的问题
- 进程只运行一个实例
- 禁止运行多个实例最简单的方法
- 系统只运行一次exe进程
- 只运行一个实例进程的方法
- Java 程序只运行一个进程--思路
- 只允许启动个一个进程
- 同一时间内相同程序只运行一个进程运行
- 禁止一个应用程序的实例在同一台机器上运行多个(C#源码)
- 禁止一个程序的多个实例同时运行的几种方法!
- 利用c#制作托盘程序,并禁止多个应用实例运行
- 关于C#禁止多个实例程序运行的详细解决
- 利用c#制作托盘程序,并禁止多个应用实例运行
- 禁止系统运行某个进程的简单方法
- 如何使用进程名禁止程序运行两个实例
- [java]collection(容器类)框架图
- AjaxControlToolkit的安装与使用
- SQL Server 2008 CTP支持PowerShell
- 读文档也是一门艺术
- MIO神达A700/A701ROM刷机教程
- 只禁止多个进程运行
- 如何开启 Windows 2000 Server 的远程桌面
- 算法题2
- 在ModalDialog中操作父窗口对象
- 延缓写入失败
- 汇编->十进制到十六进制数转换的程序实现
- P67 2-17
- 木马程序
- Portal日志开发