|
using System;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.ServiceProcess;
using System.Configuration;
using System.Configuration.Install;
using Microsoft.Win32;
namespace SystemTrayIconInSvc
{
[RunInstaller(true)]
public class SvcInstaller : Installer
{
private static readonly string SVC_NAME = "SystemTrayIconInSvc";
private static readonly string SVC_DESC = "This is a test";
public SvcInstaller()
{
Installers.Clear();
ServiceInstaller serviceInstaller = new ServiceInstaller();
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = SVC_NAME;
serviceInstaller.DisplayName = SVC_NAME;
serviceInstaller.Description = SVC_DESC;
serviceInstaller.ServicesDependedOn = new string[] { "SENS", "COMSysApp" };
Installers.Add(serviceInstaller);
ServiceProcessInstaller processInstaller = new ServiceProcessInstaller();
processInstaller.Account = ServiceAccount.LocalSystem;
processInstaller.Password = null;
processInstaller.Username = null;
Installers.Add(processInstaller);
}
protected override void OnAfterInstall(IDictionary savedState)
{
ServiceController controller = null;
ServiceController[] controllers = ServiceController.GetServices();
for (int i = 0; i < controllers.Length; i++)
{
if (controllers[i].ServiceName == SVC_NAME)
{
controller = controllers[i];
break;
}
}
if (controller == null)
{
return;
}
// if the service is not active, start it
if (controller.Status != ServiceControllerStatus.Running)
{
string[] args = { "-install" };
controller.Start(args);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Jerry is from China. He was captivated by computer programming since 13 years old when first time played with Q-Basic.
- Windows / Linux & C++
- iOS & Obj-C
- .Net & C#
- Flex/Flash & ActionScript
- HTML / CSS / Javascript
- Gaming Server programming / video, audio processing / image & graphics
Contact: vcer(at)qq.com
Chinese Blog: http://blog.csdn.net/wangjia184