论坛首页 编程语言技术论坛

VS C# 2008里只让应用程序只运行一个实例

浏览 1491 次
该帖已经被评为隐藏帖
作者 正文
   发表时间:2008-06-19  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Diagnostics;

namespace MovSysSht
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\PerfProc\Performance", true);
                if (rk != null)
                {
                    object tmpObj = rk.GetValue("Disable   Performance   Counters");
                    if (tmpObj != null && !tmpObj.Equals(0))
                    {
                        rk.SetValue("Disable   Performance   Counters", 0);
                        //要添加一个日志表明此处删除了一个注册表值  
                    }
                }
                Process[] pros = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
                if (pros.Length > 1)
                {
                    Application.Exit();
                    return;
                }
                Application.Run(new SHTMain());
           }
            catch (Exception ex) { }
        }
    }
}

论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics