12 using System.Collections.Generic;
14 using System.ServiceProcess;
18 using System.Configuration.Install;
29 static void Main(
string[] args)
31 bool mutexCreated =
false;
32 System.Threading.Mutex mutex =
new System.Threading.Mutex(
true,
"EaseFilter", out mutexCreated);
38 Console.WriteLine(
"There are another EaseFilter service instance running, can't start the second one.");
42 if (Environment.UserInteractive)
48 string command = args[0];
49 switch (command.ToLower())
51 case "-installdriver":
53 bool ret = FilterAPI.InstallDriver();
57 Console.WriteLine(
"Install driver failed:" + FilterAPI.GetLastErrorMessage());
63 case "-uninstalldriver":
65 FilterAPI.StopFilter();
67 bool ret = FilterAPI.UnInstallDriver();
71 Console.WriteLine(
"UnInstall driver failed:" + FilterAPI.GetLastErrorMessage());
77 case "-installservice":
81 ManagedInstallerClass.InstallHelper(
new string[] { Assembly.GetExecutingAssembly().Location });
85 Console.WriteLine(
"Install service failed:" + ex.Message);
91 case "-uninstallservice":
95 ManagedInstallerClass.InstallHelper(
new string[] {
"/u", Assembly.GetExecutingAssembly().Location });
99 Console.WriteLine(
"UnInstall service failed:" + ex.Message);
109 Console.WriteLine(
"Starting EaseTag console application...");
110 FilterWorker.StartService();
111 Console.WriteLine(
"\n\nPress any key to stop program");
113 FilterWorker.StopService();
117 Console.WriteLine(
"Start EaseTag service failed:" + ex.Message);
123 default:
Console.WriteLine(
"The command " + command +
" doesn't exist"); PrintUsage();
break;
136 Console.WriteLine(
"Starting EaseFilter windows service...");
137 EaseFilterService service =
new EaseFilterService();
138 ServiceBase.Run(service);
144 EventManager.WriteMessage(132,
"EaseFilterService",
EventLevel.Error,
"EaseFilter failed with error " + ex.Message);
148 Console.WriteLine(
"Exiting EaseFilter service.");
156 static void PrintUsage()
158 Console.WriteLine(
"Usage: EaseFltCSConsoleDemo command");
159 Console.WriteLine(
"Commands:");
160 Console.WriteLine(
"-InstallDriver --Install EaseFilter filter driver.");
161 Console.WriteLine(
"-UninstallDriver --Uninstall EaseFilter filter driver.");
162 Console.WriteLine(
"-InstallService --Install EaseFilter Windows service.");
163 Console.WriteLine(
"-UnInstallService ---Uninstall EaseFilter Windows service.");
164 Console.WriteLine(
"-Console ----start the console application.");