Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                List <string> arguments = new List <string>(args);

                Microsoft.Win32.SystemEvents.PowerModeChanged +=
                    new Microsoft.Win32.PowerModeChangedEventHandler(
                        SystemEvents_PowerModeChanged);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (CommandLineArgumentsContain(arguments, "INSTALL-AUTOSTART"))
                {
                    Helper.InstallAutostart();
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "REMOVE-AUTOSTART"))
                {
                    Helper.RemoveAutostart(); // Remove autostart, quit (for setup, e.g.)
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "?") || CommandLineArgumentsContain(arguments, "HELP") || CommandLineArgumentsContain(arguments, "H"))
                {
                    RTLMessageBox.Show(res.GetString("ARGS_Help"), // Show help
                                       MessageBoxIcon.Information);
                    return;
                }
                Mutex appSingleton = new Mutex(false, Application.ProductName + ".SingleInstance");
                if (appSingleton.WaitOne(0, false))
                {
                    m_mainform = new FrmGlobalStatus(arguments.ToArray());
                    Application.Run(m_mainform);
                }
                else
                {
                    if (arguments.Count > 0)
                    {
                        SimpleComm sc = new SimpleComm(4911);
                        if (!sc.client(arguments.ToArray()))
                        {
                            RTLMessageBox.Show(res.GetString("ARGS_Error"),
                                               MessageBoxIcon.Error);
                        }
                    }
                }

                appSingleton.Close();
            }
            catch (Exception ex)
            {
                //In case of 'something terible' dont disappear without a message.
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            bool noUserInteraction = false;//service process only
            try
            {
                List<string> arguments = new List<string>(args);

                Microsoft.Win32.SystemEvents.PowerModeChanged +=
                    new Microsoft.Win32.PowerModeChangedEventHandler(
                        SystemEvents_PowerModeChanged);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (CommandLineArgumentsContain(arguments, "INSTALL"))
                {
                    ServiceHelper.installService();
                    return;
                }
                if (CommandLineArgumentsContain(arguments, "UNINSTALL"))
                {
                    ServiceHelper.uninstallService();
                    return;
                }
                if (CommandLineArgumentsContain(arguments, "EXECUTESERVICE"))
                {   // EXECUTESERVICE is not to be used by the end-user but only for service installation run command
                    // this to be able to know it should start as a service.
                    noUserInteraction = true;
                    ServiceHelper.executeService();
                    return;
                }
                if (CommandLineArgumentsContain(arguments, "EXECUTESERVICEASCONSOLE"))
                {
                    ServiceHelper.executeServiceAsConsole();
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "INSTALL-AUTOSTART"))
                {
                    helper.installAutostart();
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "REMOVE-AUTOSTART"))
                {
                    helper.removeAutostart(); // Remove autostart, quit (for setup, e.g.)
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "?") || CommandLineArgumentsContain(arguments, "HELP") || CommandLineArgumentsContain(arguments, "H"))
                {
                    RTLMessageBox.Show(res.GetString("ARGS_Help"), // Show help
                    MessageBoxIcon.Information);
                    return;
                }
                Mutex appSingleton = new Mutex(false, Application.ProductName + ".SingleInstance");
                if (appSingleton.WaitOne(0, false))
                {
                    m_mainform = new FrmGlobalStatus(arguments.ToArray());
                    Application.Run(m_mainform);
                }
                else
                {
                    if (arguments.Count > 0)
                    {
                        SimpleComm sc = new SimpleComm(4911);
                        if (!sc.client(arguments.ToArray()))
                            RTLMessageBox.Show(res.GetString("ARGS_Error"),
                                MessageBoxIcon.Error);
                    }
                }

                appSingleton.Close();
            }
            catch (Exception ex)
            {
                if (noUserInteraction)
                {
                    string eventlogAppName = "OpenVPNManager";
                    if (!EventLog.SourceExists(eventlogAppName))
                        EventLog.CreateEventSource(eventlogAppName, "Application");
                    EventLog.WriteEntry(eventlogAppName, ex.ToString(), EventLogEntryType.Error, 0);
                }
                else
                    //In case of 'something terible' dont disappear without a message.
                    MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            try
            {
                List<string> arguments = new List<string>(args);

                Microsoft.Win32.SystemEvents.PowerModeChanged +=
                    new Microsoft.Win32.PowerModeChangedEventHandler(
                        SystemEvents_PowerModeChanged);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (CommandLineArgumentsContain(arguments, "INSTALL-AUTOSTART"))
                {
                    Helper.InstallAutostart();
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "REMOVE-AUTOSTART"))
                {
                    Helper.RemoveAutostart(); // Remove autostart, quit (for setup, e.g.)
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "?") || CommandLineArgumentsContain(arguments, "HELP") || CommandLineArgumentsContain(arguments, "H"))
                {
                    RTLMessageBox.Show(res.GetString("ARGS_Help"), // Show help
                    MessageBoxIcon.Information);
                    return;
                }
                Mutex appSingleton = new Mutex(false, Application.ProductName + ".SingleInstance");
                if (appSingleton.WaitOne(0, false))
                {
                    m_mainform = new FrmGlobalStatus(arguments.ToArray());
                    Application.Run(m_mainform);
                }
                else
                {
                    if (arguments.Count > 0)
                    {
                        SimpleComm sc = new SimpleComm(4911);
                        if (!sc.client(arguments.ToArray()))
                            RTLMessageBox.Show(res.GetString("ARGS_Error"),
                                MessageBoxIcon.Error);
                    }
                }

                appSingleton.Close();
            }
            catch (Exception ex)
            {
                //In case of 'something terible' dont disappear without a message.
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            bool noUserInteraction = false;//service process only

            try
            {
                List <string> arguments = new List <string>(args);

                Microsoft.Win32.SystemEvents.PowerModeChanged +=
                    new Microsoft.Win32.PowerModeChangedEventHandler(
                        SystemEvents_PowerModeChanged);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (CommandLineArgumentsContain(arguments, "INSTALL"))
                {
                    ServiceHelper.installService();
                    return;
                }
                if (CommandLineArgumentsContain(arguments, "UNINSTALL"))
                {
                    ServiceHelper.uninstallService();
                    return;
                }
                if (CommandLineArgumentsContain(arguments, "EXECUTESERVICE"))
                {   // EXECUTESERVICE is not to be used by the end-user but only for service installation run command
                    // this to be able to know it should start as a service.
                    noUserInteraction = true;
                    ServiceHelper.executeService();
                    return;
                }
                if (CommandLineArgumentsContain(arguments, "EXECUTESERVICEASCONSOLE"))
                {
                    ServiceHelper.executeServiceAsConsole();
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "INSTALL-AUTOSTART"))
                {
                    helper.installAutostart();
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "REMOVE-AUTOSTART"))
                {
                    helper.removeAutostart(); // Remove autostart, quit (for setup, e.g.)
                    return;
                }
                else if (CommandLineArgumentsContain(arguments, "?") || CommandLineArgumentsContain(arguments, "HELP") || CommandLineArgumentsContain(arguments, "H"))
                {
                    RTLMessageBox.Show(res.GetString("ARGS_Help"), // Show help
                                       MessageBoxIcon.Information);
                    return;
                }
                Mutex appSingleton = new Mutex(false, Application.ProductName + ".SingleInstance");
                if (appSingleton.WaitOne(0, false))
                {
                    m_mainform = new FrmGlobalStatus(arguments.ToArray());
                    Application.Run(m_mainform);
                }
                else
                {
                    if (arguments.Count > 0)
                    {
                        SimpleComm sc = new SimpleComm(4911);
                        if (!sc.client(arguments.ToArray()))
                        {
                            RTLMessageBox.Show(res.GetString("ARGS_Error"),
                                               MessageBoxIcon.Error);
                        }
                    }
                }

                appSingleton.Close();
            }
            catch (Exception ex)
            {
                if (noUserInteraction)
                {
                    string eventlogAppName = "OpenVPNManager";
                    if (!EventLog.SourceExists(eventlogAppName))
                    {
                        EventLog.CreateEventSource(eventlogAppName, "Application");
                    }
                    EventLog.WriteEntry(eventlogAppName, ex.ToString(), EventLogEntryType.Error, 0);
                }
                else
                {
                    //In case of 'something terible' dont disappear without a message.
                    MessageBox.Show(ex.ToString());
                }
            }
        }