The library is only on the elementary Windows system service operation, no narrated apt depth. I would like to have a coarse enough.
tin alter a number of bulk and dependencies.
/ / /
/ / / Windows Service class
/ / /
public level ServiceUtil
{
/ / /
/ / / if there
efficacy Services / / /
/ / /
/ / / exists return true, otherwise return false;
; public static bool ServiceI######isted (string serviceName)
ServiceController [] services = ServiceController.GetServices ();
foreach (ServiceController s in services)
if (s. ServiceName.ToLower () == serviceName.ToLower ())
return true;
return false;
/ / /
; / / / installation services
/ / /
/ / /
{
try
AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller ();
; myAssemblyInstaller.UseNewContext = true;
myAssemblyInstaller.Path = filepath;
myAssemblyInstaller.Install (stateSaver);
; myAssemblyInstaller.Commit (stateSaver);
; myAssemblyInstaller.Dispose ();
catch (Exception ex)
{
discard new Sy######ception (ex.Message, ex);
}
}
/ / /
; / / / uninstall service
/ / /
/ / /
{
try
AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller ();
; myAssemblyInstaller.UseNewContext = true;
myAssemblyInstaller.Path = filepath;
myAssemblyInstaller.Uninstall (null);
myAssemblyInstaller.Dispose ();
catch (Exception ex)
throw new Sy######ception (ex.Message,
womens puma, ex);
}
/ / /
/ / / determine the Windows service is running
/ / /
/ / /
/ / / true if the specified name namely sprint; otherwise, false .
/ / /
public static bool IsRun (string name)
; {
bool IsRun = false;
; try
{
; if (! ServiceI######isted (name)) return false;
; var sc = new ServiceController (name);
; if (sc.Status == ServiceControllerStatus.StartPending | | sc.Status == ServiceControllerStatus.Running)
;
; IsRun = true;
sc.Close ();
}
; catch
; IsRun = false;
return IsRun;
}
/ / /
/ / / Start Service
/ / /
/ / /
public static bool StarService (string name)
; {
try
; {
var sc = new ServiceController (name);
if (sc.Status == ServiceControllerStatus. Stopped | | sc.Status == ServiceControllerStatus.StopPending)
sc.Start ();
sc.WaitForStatus (ServiceControllerStatus.Running, new TimeSpan (0,
womens puma, 0, 10));
else
; sc.Close ();
return true;
}
grab (Exception ex)
throw new Sy######ception (ex.Message, ex);
}
/ / /
; / / / stop services
/ / /
/ / /
to stop the successful return true,
womens puma, otherwise return false;
public static bool StopService (string name)
; {
try
; {
; var sc = current ServiceController (name);
if (sc.Status == ServiceControllerStatus.Running | | sc.Status == ServiceControllerStatus.StartPending)
;
sc . Stop ();
sc. WaitForStatus (ServiceControllerStatus.Stopped, new TimeSpan (0, 0, 10));
else
;
sc.Close ();
return true;
}
catch (Exception ex)
throw new Sy######ception (ex.Message, ex);
}
/ / /
; / / / restart the service
/ / /
/ / /
restart the successful return true, otherwise return false;
public static bool RefreshService (string appoint)
return StopService (name) & & StarService (name);
Code highlighting produced along Actipro CodeHighlighter (freeware) http: / / www.CodeHighlighter.com/--> / / /
/ / / Windows Service class
; / / /
public class ServiceUtil
{
/ / /
/ / / if there
effect Services / / /
/ / /
/ / / exists return true, otherwise return false;
public static bool ServiceI######isted (string serviceName)
ServiceController [] services = ServiceController.GetServices ();
foreach (ServiceController s in services)
if (s.ServiceName.ToLower () == serviceName.ToLower ())
return true;
return false;
/ / /
; / / / installation services
/ / /
/ / /
{
try
AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller ();
; myAssemblyInstaller.UseNewContext = true;
myAssemblyInstaller.Path = filepath;
myAssemblyInstaller.Install (stateSaver);
myAssemblyInstaller.Commit (stateSaver);
; myAssemblyInstaller.Dispose ();
catch (Exception ex)
throw new Sy######ception (ex.Message, ex);
}
/ / /
; / / / uninstall service
/ / /
/ / /
{
try
AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller ();
; myAssemblyInstaller.UseNewContext = true;
myAssemblyInstaller.Path = filepath;
myAssemblyInstaller.Uninstall (null);
myAssemblyInstaller.Dispose ();
catch (Exception ex)
throw new Sy######ception (ex.Message,
womens puma, ex);
}
/ / /
/ / / make sure the Windows service is running
; / / /
/ / /
/ / /
/ / / true if the specified name is run; otherwise, false .
; / / /
public static bool IsRun (string name)
; {
bool IsRun = false;
; try
{
if (,
boots timberland 日本开始向福岛第一核电站四个反应! ServiceI######isted (name)) return false;
; var sc = new ServiceController (name);
; if (sc.Status == ServiceControllerStatus.StartPending | | sc.Status == ServiceControllerStatus.Running)
;
; IsRun = true;
sc. Close ();
}
; catch
; IsRun = false;
return IsRun;
}
/ / /
; / / / start the service
/ / /
/ / /
public static bool StarService (string name)
; {
try
; {
; var sc = new ServiceController (name);
if (sc . Status == ServiceControllerStatus.Stopped | | sc.Status == ServiceControllerStatus.StopPending)
;
sc.Start ();
sc.WaitForStatus ( ServiceControllerStatus.Running, new TimeSpan (0, 0, 10));
else
;
sc.Close ();
return true;
}
catch (Exception ex)
throw new Sy######ception (ex.Message, ex);
}
/ / /
; / / / stop services
/ / /
/ / /
stop the successful return true, otherwise return false;
public static bool StopService (string name)
{
try
{
; var sc = new ServiceController (name);
; if (sc.Status == ServiceControllerStatus.Running | | sc.Status == ServiceControllerStatus.StartPending)
;
; sc.Stop ();
sc.WaitForStatus (ServiceControllerStatus.Stopped, new TimeSpan (0,
womens puma, 0,
womens puma,
Mens Christian Audigier Italian Prime Minister Sil, 10));
else
;
sc.Close () ;
return true;
}
catch (Exception ex)
throw new Sy######ception (ex.Message, ex);
}
/ / /
/ / / restart the service
/ / / ;
/ / /
restart the successful return true,
men timberland boots ER ... the heading of silence, otherwise return artificial;
public static bool RefreshService (string name)
; return StopService (name) & & StarService (name);
}