EaseFilter Demo Project
FileMonitorService/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 FileMonitorService
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 
43 
44  if (Environment.UserInteractive)
45  {
46 
47 
48  if (args.Length > 0)
49  {
50  string command = args[0];
51  switch (command.ToLower())
52  {
53  case "-installdriver":
54  {
55  bool ret = FilterAPI.InstallDriver();
56 
57  if (!ret)
58  {
59  Console.WriteLine("Install driver failed:" + FilterAPI.GetLastErrorMessage());
60  }
61 
62  break;
63  }
64 
65  case "-uninstalldriver":
66  {
67  FilterAPI.StopFilter();
68 
69  bool ret = FilterAPI.UnInstallDriver();
70 
71  if (!ret)
72  {
73  Console.WriteLine("UnInstall driver failed:" + FilterAPI.GetLastErrorMessage());
74  }
75 
76  break;
77  }
78 
79  case "-installservice":
80  {
81  try
82  {
83  ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
84  }
85  catch (Exception ex)
86  {
87  Console.WriteLine("Install service failed:" + ex.Message);
88  }
89 
90  break;
91  }
92 
93  case "-uninstallservice":
94  {
95  try
96  {
97  ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
98  }
99  catch (Exception ex)
100  {
101  Console.WriteLine("UnInstall service failed:" + ex.Message);
102  }
103 
104  break;
105  }
106 
107  case "-console":
108  {
109  try
110  {
111  Console.WriteLine("Starting FileMonitor console application...");
112 
115 
116  FilterWorker.StartService();
117  Console.WriteLine("\n\nPress any key to stop program");
118  Console.Read();
119  FilterWorker.StopService();
120  }
121  catch (Exception ex)
122  {
123  Console.WriteLine("Start FileMonitor service failed:" + ex.Message);
124  }
125 
126  break;
127  }
128 
129  default: Console.WriteLine("The command " + command + " doesn't exist"); PrintUsage(); break;
130 
131  }
132 
133  }
134  else
135  {
136  PrintUsage();
137  }
138 
139  }
140  else
141  {
142  Console.WriteLine("Starting EaseFilter windows service...");
143  EaseFilterService service = new EaseFilterService();
144  ServiceBase.Run(service);
145 
146  }
147  }
148  catch (Exception ex)
149  {
150  EventManager.WriteMessage(132, "EaseFilterService", EventLevel.Error, "EaseFilter failed with error " + ex.Message);
151  }
152  finally
153  {
154  Console.WriteLine("Exiting EaseFilter service.");
155  GlobalConfig.Stop();
156  mutex.Close();
157  }
158 
159 
160  }
161 
162  static void PrintUsage()
163  {
164  Console.WriteLine("Usage: FileMonitorService command");
165  Console.WriteLine("Commands:");
166  Console.WriteLine("-InstallDriver --Install EaseFilter filter driver.");
167  Console.WriteLine("-UninstallDriver --Uninstall EaseFilter filter driver.");
168  Console.WriteLine("-InstallService --Install EaseFilter Windows service.");
169  Console.WriteLine("-UnInstallService ---Uninstall EaseFilter Windows service.");
170  Console.WriteLine("-Console ----start the console application.");
171  }
172 
173  }
174 }
static void CopyOSPlatformDependentFiles()
Definition: Utils.cs:92
static EventOutputType EventOutputType

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