判断是否在一台电脑只能打开一次

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

namespace B2B_Import
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {
                bool ret;
                System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out ret);
                if (ret)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    RegistryKey loca_chek = Registry.LocalMachine;
                    RegistryKey run_Check = loca_chek.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
                    if (run_Check.GetValue("WinForm").ToString().ToLower() != "false")
                    {
                        Application.Run(new Main());
                    }
                    else
                    {
                        Application.Run(new Login());
                    }
                }
            }
            catch
            {
                //MessageBox.Show(ex.Message);
                Application.Run(new Login());
            }
        }
    }
}

posted @ 2017-07-17 16:13  游林  阅读(140)  评论(0编辑  收藏  举报