3 using System
.Collections
;
4 using System
.ComponentModel
;
5 using System
.ServiceProcess
;
6 using System
.Configuration
.Install
;
14 public static class SillyHelper
16 public static void print(this Stream stream
, string s
)
18 byte[] utf8
= s
.ToUTF8();
19 stream
.Write(utf8
, 0, utf8
.Length
);
25 public class ProjectInstaller
: Installer
27 ServiceProcessInstaller spi
;
30 public ProjectInstaller()
32 si
= new ServiceInstaller();
33 si
.ServiceName
= "ServTest";
34 si
.Description
= "Description++";
35 si
.StartType
= ServiceStartMode
.Automatic
;
37 spi
= new ServiceProcessInstaller();
38 spi
.Account
= ServiceAccount
.LocalSystem
;
47 public class ServTest
: ServiceBase
55 f
= File
.Open("/tmp/test.txt",
58 FileShare
.ReadWrite
| FileShare
.Delete
);
61 t
.Elapsed
+= new ElapsedEventHandler(t_Elapsed
);
63 ServiceName
= "ServTest";
66 static void Main(string[] args
)
68 ServTest o
= new ServTest();
69 o
.f
.print(String
.Format("args: ({0}) ({1}) {2}\n",
71 Environment
.UserInteractive
,
74 if (Environment
.UserInteractive
75 || (args
.Length
> 0 && args
[0] == "-f"))
77 Console
.WriteLine("Running in foreground!");
84 Console
.WriteLine("Running in background!");
89 protected override void OnStart(string[] args
)
91 f
.print("Service started.\n");
95 protected override void OnStop()
98 f
.print("Service stopped.\n");
101 private void t_Elapsed(object sender
, ElapsedEventArgs e
)
103 f
.print("Timer elapsed! " + (++i
).ToString() + "\n");