예제 #1
0
        static void Main()
        {
            ClientInfo.TypeOfProgram = typeof(Program);

            if (StringUtil.IsDevelopMode() == false)
            {
                ClientInfo.PrepareCatchException();
            }

            // http://stackoverflow.com/questions/184084/how-to-force-c-sharp-net-app-to-run-only-one-instance-in-windows

            context = ExecutionContext.Capture();
            mutex   = new Mutex(true,
                                "{CF1B7B4A-C7ED-4DB8-B5CC-59A067880F92}",
                                out bool createdNew);
            try
            {
                List <string> args = StringUtil.GetCommandLineArgs();

                if (createdNew ||
                    args.IndexOf("newinstance") != -1)
                {
                    ClientInfo.AddShortcutToStartupGroup("dp2-RFID中心");

                    ProgramUtil.SetDpiAwareness();

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    _mainForm = new MainForm();
                    Application.Run(_mainForm);
                }
                else
                {
                    Process current = Process.GetCurrentProcess();
                    foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            API.SetForegroundWindow(process.MainWindowHandle);
                            if (API.IsIconic(process.MainWindowHandle))
                            {
                                // API.ShowWindow(process.MainWindowHandle, API.SW_SHOW);
                                API.ShowWindow(process.MainWindowHandle, API.SW_RESTORE);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (mutex != null)
                {
                    mutex.Close();
                }
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: zgren/dp2
        static void Main()
        {
            ClientInfo.TypeOfProgram = typeof(Program);

            if (StringUtil.IsDevelopMode() == false)
            {
                ClientInfo.PrepareCatchException();
            }

            ProgramUtil.SetDpiAwareness();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
예제 #3
0
파일: Program.cs 프로젝트: zszqwe/dp2
        static void Main()
        {
            ClientVersion = Assembly.GetAssembly(typeof(Program)).GetName().Version.ToString();
#if NO
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
#endif
            if (IsDevelopMode() == false)
            {
                PrepareCatchException();
            }

            ProgramUtil.SetDpiAwareness();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            _mainForm = new MainForm();
            Application.Run(_mainForm);
        }
예제 #4
0
파일: Program.cs 프로젝트: kevinlau2015/dp2
        static void Main()
        {
            string folderPath   = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string assemblyPath = Path.Combine(folderPath, IntPtr.Size == 8 ? "x64" : "x86");

            SetDllDirectory(assemblyPath);

            //AppDomain currentDomain = AppDomain.CurrentDomain;
            //currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromSameFolder);

            ClientInfo.TypeOfProgram = typeof(Program);

            if (StringUtil.IsDevelopMode() == false)
            {
                ClientInfo.PrepareCatchException();
            }

            // http://stackoverflow.com/questions/184084/how-to-force-c-sharp-net-app-to-run-only-one-instance-in-windows

            context = ExecutionContext.Capture();
            mutex   = new Mutex(true,
                                "{CF1B7B4A-C7ED-4DB8-B5CC-59A067880F92}",
                                out bool createdNew);
            try
            {
                List <string> args = StringUtil.GetCommandLineArgs();

                if (createdNew ||
                    args.IndexOf("newinstance") != -1)
                {
                    // ClientInfo.AddShortcutToStartupGroup("dp2-RFID中心");
                    ClientInfo.RemoveShortcutFromStartupGroup("dp2-RFID中心");

                    ProgramUtil.SetDpiAwareness();

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    _mainForm = new MainForm();
                    Application.Run(_mainForm);
                }
                else
                {
                    Process current = Process.GetCurrentProcess();
                    foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            API.SetForegroundWindow(process.MainWindowHandle);
                            if (API.IsIconic(process.MainWindowHandle))
                            {
                                // API.ShowWindow(process.MainWindowHandle, API.SW_SHOW);
                                API.ShowWindow(process.MainWindowHandle, API.SW_RESTORE);
                            }
                            else
                            {
                                // 用 .net remoting 通讯
                                MainForm.CallActivate("ipc://RfidChannel/RfidServer");
                            }
                        }
                    }
                }
            }
            finally
            {
                if (mutex != null)
                {
                    mutex.Close();
                }
            }
        }
예제 #5
0
        static void Main()
        {
            ClientInfo.TypeOfProgram = typeof(Program);

            if (StringUtil.IsDevelopMode() == false)
            {
                ClientInfo.PrepareCatchException();
            }

            // http://stackoverflow.com/questions/184084/how-to-force-c-sharp-net-app-to-run-only-one-instance-in-windows

            context = ExecutionContext.Capture();
            mutex   = new Mutex(true,
                                "{75FB942B-5E25-4228-9093-D220FFEDB33C}",
                                out bool createdNew);
            try
            {
                List <string> args = StringUtil.GetCommandLineArgs();

                if (createdNew ||
                    args.IndexOf("newinstance") != -1)
                {
                    // 删除以前接口程序的 shortcut
                    ClientInfo.RemoveShortcutFromStartupGroup("dp2-中控指纹阅读器接口");

                    // ClientInfo.AddShortcutToStartupGroup("dp2-指纹中心");
                    ClientInfo.RemoveShortcutFromStartupGroup("dp2-指纹中心");

                    ProgramUtil.SetDpiAwareness();

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    _mainForm = new MainForm();
                    Application.Run(_mainForm);
                }
                else
                {
                    Process current = Process.GetCurrentProcess();
                    foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            API.SetForegroundWindow(process.MainWindowHandle);
                            if (API.IsIconic(process.MainWindowHandle))
                            {
                                // API.ShowWindow(process.MainWindowHandle, API.SW_SHOW);
                                API.ShowWindow(process.MainWindowHandle, API.SW_RESTORE);
                            }
                            else
                            {
                                // 用 .net remoting 通讯
                                MainForm.CallActivate("ipc://FingerprintChannel/FingerprintServer");

#if NO
                                // Yes...Bring existing instance to top and activate it.
                                PostMessage(
                                    (IntPtr)HWND_BROADCAST,
                                    WM_MY_MSG,
                                    new IntPtr(0xCDCD),
                                    new IntPtr(0xEFEF));
#endif
                                // API.PostMessage(process.MainWindowHandle, MainForm.WM_SHOW1, 0, 0);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (mutex != null)
                {
                    mutex.Close();
                }
            }

#if NO
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
#endif
        }
예제 #6
0
        static void Main()
        {
            ClientVersion = Assembly.GetAssembly(typeof(Program)).GetName().Version.ToString();

            List <string> args = StringUtil.GetCommandLineArgs();

            // TODO: 检查 Windows 环境,如果可行就提示安装更高版本(如果更高版本的菜单事项还没有的话)

            // 绿色安装方式下,如果没有按住 Ctrl 键启动,会优先用 ClickOnce 方式启动
            if (ApplicationDeployment.IsNetworkDeployed == false &&
                Control.ModifierKeys != Keys.Control &&
                args.IndexOf("green") == -1 &&
                StringUtil.IsDevelopMode() == false)
            {
                string strShortcutFilePath = PathUtil.GetShortcutFilePath("DigitalPlatform/dp2 V3/dp2内务 V3");
                if (File.Exists(strShortcutFilePath) == true)
                {
                    try
                    {
                        Process.Start(strShortcutFilePath);
                        return;
                    }
                    catch
                    {
                    }
                }
            }

#if NO
            if (ApplicationDeployment.IsNetworkDeployed &&
                ApplicationDeployment.CurrentDeployment.ActivationUri != null)
            {
                // string startupUrl = ApplicationDeployment.CurrentDeployment.ActivationUri.ToString();
                MessageBox.Show("first=" + ApplicationDeployment.CurrentDeployment.ActivationUri.Query);
                args = StringUtil.GetClickOnceCommandLineArgs(ApplicationDeployment.CurrentDeployment.ActivationUri.Query);
            }

            // Also tack on any activation args at the back
            var activationArgs = AppDomain.CurrentDomain.SetupInformation.ActivationArguments;
            if (activationArgs != null && activationArgs.ActivationData != null)
            {
                args.AddRange(activationArgs.ActivationData);
                MessageBox.Show("second=" + StringUtil.MakePathList(args));
            }
#endif

            // http://stackoverflow.com/questions/184084/how-to-force-c-sharp-net-app-to-run-only-one-instance-in-windows

            context = ExecutionContext.Capture();
            mutex   = new Mutex(true,
                                "{A810CFB4-D932-4821-91D4-4090C84C5C68}",
                                out bool createdNew);
            try
            {
                if (createdNew
                    // || _suppressMutex
                    || args.IndexOf("newinstance") != -1)
                {
                    if (StringUtil.IsDevelopMode() == false)
                    {
                        PrepareCatchException();
                    }

                    ProgramUtil.SetDpiAwareness();
#if NO
                    // Vista on up = 6
                    // http://stackoverflow.com/questions/17406850/how-can-we-check-if-the-current-os-is-win8-or-blue
                    if (
                        Environment.OSVersion.Version.Major > 6 ||
                        (Environment.OSVersion.Version.Major == 6 &&
                         Environment.OSVersion.Version.Minor >= 2)
                        )
                    {
                        // http://stackoverflow.com/questions/32148151/setprocessdpiawareness-not-having-effect

                        /*
                         * I've been trying to disable the DPI awareness on a ClickOnce application.
                         * I quickly found out, it is not possible to specify it in the manifest, because ClickOnce does not support asm.v3 in the manifest file.
                         * */
                        try
                        {
                            // https://msdn.microsoft.com/en-us/library/windows/desktop/dn302122(v=vs.85).aspx
                            var result = SetProcessDpiAwareness(PROCESS_DPI_AWARENESS.Process_System_DPI_Aware);
                            // var setDpiError = Marshal.GetLastWin32Error();
                        }
                        catch
                        {
                        }

#if NO
                        PROCESS_DPI_AWARENESS awareness;
                        GetProcessDpiAwareness(Process.GetCurrentProcess().Handle, out awareness);
                        var getDpiError = Marshal.GetLastWin32Error();
#endif
                    }
#endif

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    _mainForm = new MainForm();
                    Application.Run(_mainForm);
                }
                else
                {
                    Process current = Process.GetCurrentProcess();
                    foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            API.SetForegroundWindow(process.MainWindowHandle);
                            if (API.IsIconic(process.MainWindowHandle))
                            {
                                // API.ShowWindow(process.MainWindowHandle, API.SW_SHOW);
                                API.ShowWindow(process.MainWindowHandle, API.SW_RESTORE);
                            }
                            // break;
                        }
                    }
                }
            }
            finally
            {
                if (mutex != null)
                {
                    mutex.Close();
                }
            }
        }
예제 #7
0
파일: Program.cs 프로젝트: zhangandding/dp2
        static void Main()
        {
            ClientVersion = Assembly.GetAssembly(typeof(Program)).GetName().Version.ToString();

            var wi = WindowsIdentity.GetCurrent();
            var wp = new WindowsPrincipal(wi);

            bool runAsAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator);

            if (!runAsAdmin /*&& Environment.OSVersion.Version.Major >= 6*/)
            {
                string strDataDir = "";
                if (ApplicationDeployment.IsNetworkDeployed == true)
                {
                    strDataDir = Application.LocalUserAppDataPath;
                }
                else
                {
                    strDataDir = Environment.CurrentDirectory;
                }

                string strUserDir = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
                    "dp2LibraryXE_v1");
                // PathUtil.CreateDirIfNeed(strUserDir);


                // It is not possible to launch a ClickOnce app as administrator directly,
                // so instead we launch the app as administrator in a new process.
                var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);

                // The following properties run the new process as administrator
                processInfo.UseShellExecute = true;
                processInfo.Verb            = "runas";
                processInfo.Arguments       = "\"datadir=" + strDataDir
                                              + "\" \"userdir=" + strUserDir + "\"";

                if (ApplicationDeployment.IsNetworkDeployed &&
                    ApplicationDeployment.CurrentDeployment.IsFirstRun == true)
                {
                    processInfo.Arguments += " \"firstrun\"";
                }

                // Start the new process
                try
                {
                    Process.Start(processInfo);
                }
                catch (Exception)
                {
                    // The user did not allow the application to run as administrator
                    //MessageBox.Show("Sorry, but I don't seem to be able to start " +
                    //   "this program with administrator rights!");
                    MessageBox.Show("dp2library XE 无法运行。\r\n\r\n因为监听 net.pipe 或 http 协议的需要,必须在 Administrator 权限下才能运行");
                }

                // Shut down the current process
                Application.Exit();
            }
            else
            {
#if NO
                // firstrun 参数
                bool     bFirstRun = false;
                string[] args      = Environment.GetCommandLineArgs();
                if (args != null && args.Length >= 2)
                {
                    bFirstRun = Array.IndexOf(args, "firstrun") != -1;
                    // MessageBox.Show("first run=" + bFirstRun);
                }

                // 2018/6/25
                try
                {
                    if (bFirstRun)
                    {
                        KillV2Process();    // 安装后第一次运行,Kill 所有其他 dp2libraryxe process。避免正在运行中的旧版本程序导致当前程序无法监听成功
                    }
                }
                catch
                {
                }
#endif

#if NO
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
                // SingleInstanceApplication.Run(new MainForm(), StartupNextInstanceHandler);
#endif
                // http://stackoverflow.com/questions/184084/how-to-force-c-sharp-net-app-to-run-only-one-instance-in-windows
                bool createdNew = true;
                // mutex name need contains windows account name. or us programes file path, hashed
                using (Mutex mutex = new Mutex(true, "dp2libraryXE V3", out createdNew))
                {
                    if (createdNew)
                    {
#if NO
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        Application.Run(new MainForm());
                        // SingleInstanceApplication.Run(new MainForm(), StartupNextInstanceHandler);
#endif
                        if (StringUtil.IsDevelopMode() == false)
                        {
                            PrepareCatchException();
                        }

                        ProgramUtil.SetDpiAwareness();

                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        _mainForm = new MainForm();
                        Application.Run(_mainForm);
                    }
                    else
                    {
                        Process current = Process.GetCurrentProcess();
                        foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                        {
                            if (process.Id != current.Id)
                            {
                                API.SetForegroundWindow(process.MainWindowHandle);
                                break;
                            }
                        }
                    }
                }

                /*
                 * http://www.cnblogs.com/riasky/p/3481795.html
                 * * 在Terminal Services下运行时, computer-wide Mutex 只有在同一个terminal server session 中的程序可见, 如果要让它在所有 Terminal Serverces sessions 可见, 则需要在它名字前面加上\.
                 *
                 *
                 * */
            }
        }
예제 #8
0
        static void Main()
        {
            if (StringUtil.IsDevelopMode() == false)
            {
                ClientInfo.PrepareCatchException();
            }

            // http://stackoverflow.com/questions/184084/how-to-force-c-sharp-net-app-to-run-only-one-instance-in-windows

            context = ExecutionContext.Capture();
            mutex   = new Mutex(true,
                                "{75FB942B-5E25-4228-9093-D220FFEDB33C}",
                                out bool createdNew);
            try
            {
                List <string> args = StringUtil.GetCommandLineArgs();

                if (createdNew ||
                    args.IndexOf("newinstance") != -1)
                {
                    // 删除以前接口程序的 shortcut
                    ClientInfo.RemoveShortcutFromStartupGroup("dp2-中控指纹阅读器接口");

                    ClientInfo.AddShortcutToStartupGroup("dp2-指纹中心");

                    ProgramUtil.SetDpiAwareness();

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    _mainForm = new MainForm();
                    Application.Run(_mainForm);
                }
                else
                {
                    Process current = Process.GetCurrentProcess();
                    foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            API.SetForegroundWindow(process.MainWindowHandle);
                            if (API.IsIconic(process.MainWindowHandle))
                            {
                                // API.ShowWindow(process.MainWindowHandle, API.SW_SHOW);
                                API.ShowWindow(process.MainWindowHandle, API.SW_RESTORE);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (mutex != null)
                {
                    mutex.Close();
                }
            }

#if NO
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
#endif
        }