EaseFilter Demo Project
EaseFltCSConsoleDemo/Program.cs
Go to the documentation of this file.
1 //
3 // (C) Copyright 2012 EaseFilter Technologies Inc.
4 // All Rights Reserved
5 //
6 // This software is part of a licensed software product and may
7 // only be used or copied in accordance with the terms of that license.
8 //
10 
11 using System;
12 using System.Collections.Generic;
13 using System.Linq;
14 using System.ServiceProcess;
15 using System.Text;
16 using System.IO;
17 using System.Reflection;
18 using System.Configuration.Install;
19 
21 
22 namespace EaseFltCSConsoleDemo
23 {
24  static class program
25  {
29  static void Main(string[] args)
30  {
31  bool mutexCreated = false;
32  System.Threading.Mutex mutex = new System.Threading.Mutex(true, "EaseFilter", out mutexCreated);
33 
34  try
35  {
36  if (!mutexCreated)
37  {
38  Console.WriteLine("There are another EaseFilter service instance running, can't start the second one.");
39  return;
40  }
41 
42  if (Environment.UserInteractive)
43  {
44 
45 
46  if (args.Length > 0)
47  {
48  string command = args[0];
49  switch (command.ToLower())
50  {
51  case "-installdriver":
52  {
53  bool ret = FilterAPI.InstallDriver();
54 
55  if (!ret)
56  {
57  Console.WriteLine("Install driver failed:" + FilterAPI.GetLastErrorMessage());
58  }
59 
60  break;
61  }
62 
63  case "-uninstalldriver":
64  {
65  FilterAPI.StopFilter();
66 
67  bool ret = FilterAPI.UnInstallDriver();
68 
69  if (!ret)
70  {
71  Console.WriteLine("UnInstall driver failed:" + FilterAPI.GetLastErrorMessage());
72  }
73 
74  break;
75  }
76 
77  case "-installservice":
78  {
79  try
80  {
81  ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
82  }
83  catch (Exception ex)
84  {
85  Console.WriteLine("Install service failed:" + ex.Message);
86  }
87 
88  break;
89  }
90 
91  case "-uninstallservice":
92  {
93  try
94  {
95  ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
96  }
97  catch (Exception ex)
98  {
99  Console.WriteLine("UnInstall service failed:" + ex.Message);
100  }
101 
102  break;
103  }
104 
105  case "-console":
106  {
107  try
108  {
109  Console.WriteLine("Starting EaseTag console application...");
110  FilterWorker.StartService();
111  Console.WriteLine("\n\nPress any key to stop program");
112  Console.Read();
113  FilterWorker.StopService();
114  }
115  catch (Exception ex)
116  {
117  Console.WriteLine("Start EaseTag service failed:" + ex.Message);
118  }
119 
120  break;
121  }
122 
123  default: Console.WriteLine("The command " + command + " doesn't exist"); PrintUsage(); break;
124 
125  }
126 
127  }
128  else
129  {
130  PrintUsage();
131  }
132 
133  }
134  else
135  {
136  Console.WriteLine("Starting EaseFilter windows service...");
137  EaseFilterService service = new EaseFilterService();
138  ServiceBase.Run(service);
139 
140  }
141  }
142  catch (Exception ex)
143  {
144  EventManager.WriteMessage(132, "EaseFilterService", EventLevel.Error, "EaseFilter failed with error " + ex.Message);
145  }
146  finally
147  {
148  Console.WriteLine("Exiting EaseFilter service.");
149  GlobalConfig.Stop();
150  mutex.Close();
151  }
152 
153 
154  }
155 
156  static void PrintUsage()
157  {
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.");
165  }
166 
167  }
168 }

Social Network


Services Overview

Architect, implement and test file system filter drivers for a wide range of functionality. We can offer several levels of assistance to meet your specific.

Contact Us

You are welcome to contact us for salse or partnership.

Sales: sales@easefilter.com
Support: support@easefilter.com
Info: info@easefilter.com