コード例 #1
0
 protected override void OnStop()
 {
     FilterWorker.StopService();
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: xuewei305/FilterDriver
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            bool mutexCreated = false;

            System.Threading.Mutex mutex = new System.Threading.Mutex(true, "EaseFilter", out mutexCreated);

            try
            {
                if (!mutexCreated)
                {
                    Console.WriteLine("There are another EaseFilter service instance running, can't start the second one.");
                    return;
                }

                if (Environment.UserInteractive)
                {
                    if (args.Length > 0)
                    {
                        string command = args[0];
                        switch (command.ToLower())
                        {
                        case "-installdriver":
                        {
                            bool ret = FilterAPI.InstallDriver();

                            if (!ret)
                            {
                                Console.WriteLine("Install driver failed:" + FilterAPI.GetLastErrorMessage());
                            }

                            break;
                        }

                        case "-uninstalldriver":
                        {
                            FilterAPI.StopFilter();

                            bool ret = FilterAPI.UnInstallDriver();

                            if (!ret)
                            {
                                Console.WriteLine("UnInstall driver failed:" + FilterAPI.GetLastErrorMessage());
                            }

                            break;
                        }

                        case "-installservice":
                        {
                            try
                            {
                                ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Install service failed:" + ex.Message);
                            }

                            break;
                        }

                        case "-uninstallservice":
                        {
                            try
                            {
                                ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("UnInstall service failed:" + ex.Message);
                            }

                            break;
                        }

                        case "-console":
                        {
                            try
                            {
                                Console.WriteLine("Starting EaseTag console application...");
                                FilterWorker.StartService();
                                Console.WriteLine("\n\nPress any key to stop program");
                                Console.Read();
                                FilterWorker.StopService();
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Start EaseTag service failed:" + ex.Message);
                            }

                            break;
                        }

                        default: Console.WriteLine("The command " + command + " doesn't exist"); PrintUsage(); break;
                        }
                    }
                    else
                    {
                        PrintUsage();
                    }
                }
                else
                {
                    Console.WriteLine("Starting EaseFilter windows service...");
                    EaseFilterService service = new EaseFilterService();
                    ServiceBase.Run(service);
                }
            }
            catch (Exception ex)
            {
                EventManager.WriteMessage(132, "EaseFilterService", EventLevel.Error, "EaseFilter failed with error " + ex.Message);
            }
            finally
            {
                Console.WriteLine("Exiting EaseFilter service.");
                GlobalConfig.Stop();
                mutex.Close();
            }
        }
コード例 #3
0
 protected override void OnStart(string[] args)
 {
     FilterWorker.StartService();
 }