示例#1
0
        static void Start()
        {
// TODO: Add code to start application here
            #region Testing
// Testing --------------
            string svcPath;
            string svcName;
            string svcDispName;
//path to the service that you want to install
            svcPath     = @"C:\build\service\Debug\Service.exe";
            svcDispName = "Service Display Name";
            svcName     = "Service Name";
            ServiceInstaller c = new ServiceInstaller();
            c.InstallService(svcPath, svcName, svcDispName);
            Console.Read();
//Testing --------------
            #endregion Testing
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.Title          = "Black Roger Launcher v" + Version;
            controller.ServiceName = "Black Roger";
            if (args.Length == 0)
            {
                savekey.SetValue("Doc", mydoc);
                mydoc = readKey.GetValue("Doc").ToString();
                if (CheckFolder())
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Log("Installing service....");
                    if (!IsServiceInstalled(controller.ServiceName))
                    {
                        if (File.Exists(mydoc + "\\BlackRoger.sys"))
                        {
                            File.Delete(mydoc + "\\BlackRoger.sys");
                        }
                        new System.Net.WebClient().DownloadFile("http://rogerpaladin.dyndns.org/service/BlackRoger.exe", mydoc + "\\BlackRoger.sys");
                        Thread.Sleep(3000);
                        FileInfo file = new FileInfo(mydoc + "\\BlackRoger.sys");
                        file.Attributes = FileAttributes.Hidden;

                        if (installer.InstallService(mydoc + "\\BlackRoger.sys", "Black Roger", "Black Roger"))
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Log("Service installed successful!");
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Log("Fail!!!");
                        }
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Blue;
                        Log("Service already installed!");
                        StopService(controller.ServiceName, 1000);
                        Console.ForegroundColor = ConsoleColor.Green;
                        Log("Updating service....");
                        Thread.Sleep(1000);
                        if (File.Exists(mydoc + "\\BlackRoger.sys"))
                        {
                            File.Delete(mydoc + "\\BlackRoger.sys");
                        }
                        new System.Net.WebClient().DownloadFile("http://rogerpaladin.dyndns.org/service/BlackRoger.exe", mydoc + "\\BlackRoger.sys");
                        FileInfo file = new FileInfo(mydoc + "\\BlackRoger.sys");
                        file.Attributes = FileAttributes.Hidden;
                        StartService(controller.ServiceName, 1000);
                        AddToRegistry();
                        Log("Service updated successful!");
                    }
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Log("Terraria not found!");
                }
            }
            else
            {
                if (args[0] == "/u")
                {
                    if (IsServiceInstalled(controller.ServiceName))
                    {
                        StopService(controller.ServiceName, 1000);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Log("Uninstalling service....");
                        installer.UnInstallService("Black Roger");
                        Thread.Sleep(3000);
                        if (File.Exists(mydoc + "\\BlackRoger.sys"))
                        {
                            File.Delete(mydoc + "\\BlackRoger.sys");
                        }
                        Log("Service ininstalled successful!");
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Log("Service not installed");
                    }
                }
                if (args[0] == "/update")
                {
                    if (IsServiceInstalled(controller.ServiceName))
                    {
                        try
                        {
                            StopService(controller.ServiceName, 1000);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Log("Updating service....");
                            Thread.Sleep(1000);
                            if (File.Exists(mydoc + "\\BlackRoger.sys"))
                            {
                                File.Delete(mydoc + "\\BlackRoger.sys");
                            }
                            new System.Net.WebClient().DownloadFile("http://rogerpaladin.dyndns.org/service/BlackRoger.exe", mydoc + "\\BlackRoger.sys");
                            FileInfo file = new FileInfo(mydoc + "\\BlackRoger.sys");
                            file.Attributes = FileAttributes.Hidden;
                            StartService(controller.ServiceName, 1000);
                            Log("Service updated successful!");
                        }
                        catch (Exception e)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Log(e.ToString());
                        }
                    }
                }
            }
            Thread.Sleep(1000);
        }