Configuration file access wrapper
コード例 #1
0
        static void Main(string[] args)
        {
            // Set up the crash dump handler.
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(unhandledException);

            cultureInfo = new System.Globalization.CultureInfo("en-GB");
            settingsManager = new SettingsManager();
            cloudFlareAPI = new CloudFlareAPI();

            if (args.Length > 0)
            {
                if (args[0] == "/service")
                {
                    runService();
                    return;
                }

                if (args[0] == "/install")
                {
                    if(!isAdmin)
                    {
                        AttachConsole( -1 /*ATTACH_PARENT_PROCESS*/ );
                        Console.WriteLine("Need to be running from an elevated (Administrator) command prompt.");
                        FreeConsole();
                        return;
                    }

                    TransactedInstaller ti = new TransactedInstaller();
                    ti.Installers.Add(new ServiceInstaller());
                    ti.Context = new InstallContext("", null);
                    ti.Context.Parameters["assemblypath"] = "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" /service";
                    ti.Install(new System.Collections.Hashtable());
                    ti.Dispose();
                    return;
                }

                if (args[0] == "/uninstall")
                {
                    if (!isAdmin)
                    {
                        AttachConsole(-1 /*ATTACH_PARENT_PROCESS*/ );
                        Console.WriteLine("Need to be running from an elevated (Administrator) command prompt.");
                        FreeConsole();
                        return;
                    }

                    TransactedInstaller ti = new TransactedInstaller();
                    ti.Installers.Add(new ServiceInstaller());
                    ti.Context = new System.Configuration.Install.InstallContext("", null);
                    ti.Context.Parameters["assemblypath"] = "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" /service";
                    ti.Uninstall(null);
                    ti.Dispose();
                    return;
                }
            }

            runGUI();
            return;

        }//end Main()
コード例 #2
0
        static void Main(string[] args)
        {
            // Set up the crash dump handler.
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(unhandledException);

            cultureInfo = new System.Globalization.CultureInfo("en-GB");
            settingsManager = new SettingsManager();
            cloudFlareAPI = new CloudFlareAPI();

            if (!Environment.UserInteractive || args.Length > 0 && args[0] == "/service")
            {
                runService();
                return;
            }

            if (args.Length > 0)
            {
                if (args[0] == "/install")
                {
                    TransactedInstaller ti = new TransactedInstaller();
                    ti.Installers.Add(new ServiceInstaller());
                    ti.Context = new InstallContext("", null);
                    ti.Context.Parameters["assemblypath"] = "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" /service";
                    ti.Install(new System.Collections.Hashtable());
                    ti.Dispose();
                    return;
                }

                if (args[0] == "/uninstall")
                {
                    TransactedInstaller ti = new TransactedInstaller();
                    ti.Installers.Add(new ServiceInstaller());
                    ti.Context = new System.Configuration.Install.InstallContext("", null);
                    ti.Context.Parameters["assemblypath"] = "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" /service";
                    ti.Uninstall(null);
                    ti.Dispose();
                    return;
                }
            }

            runGUI();
        }