-
Notifications
You must be signed in to change notification settings - Fork 13
/
ServiceUtility.cs
39 lines (32 loc) · 1.2 KB
/
ServiceUtility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace MemCacheDManager
{
public static class ServiceUtility
{
public static void UninstallService(string serviceName)
{
System.ServiceProcess.ServiceInstaller si = new System.ServiceProcess.ServiceInstaller();
si.Context = new System.Configuration.Install.InstallContext();
si.ServiceName = serviceName;
si.Uninstall(null);
}
public static void InstallService(string serviceName, string displayName, string description, string assemblyPath)
{
System.ServiceProcess.ServiceProcessInstaller spi = new System.ServiceProcess.ServiceProcessInstaller();
spi.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
System.ServiceProcess.ServiceInstaller si = new System.ServiceProcess.ServiceInstaller();
si.Description = description;
si.DisplayName = displayName;
si.ServiceName = serviceName;
si.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
si.Context = new System.Configuration.Install.InstallContext();
si.Context.Parameters.Add("assemblyPath", assemblyPath);
si.Parent = spi;
Hashtable stateSaver = new Hashtable();
si.Install(stateSaver);
}
}
}