服务程序与桌面交互
原文出处:
http://www.codeproject.com/KB/install/cswindowsservicedesktop.aspx
All the services are in the registry under the following key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
Collapse | Copy Code
public WindowsServiceInstaller()
{
// This call is required by the Designer.
InitializeComponent();
ServiceInstaller si = new ServiceInstaller();
si.ServiceName = "WindowsService1";
si.DisplayName = "WindowsService1";
si.StartType = ServiceStartMode.Manual;
this.Installers.Add(si);
ServiceProcessInstaller spi = new ServiceProcessInstaller();
spi.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
spi.Password = null;
spi.Username = null;
this.Installers.Add(spi);
放在override install 中
// Here is where we set the bit on the value in the registry.
// Grab the subkey to our service
RegistryKey ckey = Registry.LocalMachine.OpenSubKey(
@"SYSTEM\CurrentControlSet\Services\WindowsService1", true);
// Good to always do error checking!
if(ckey != null)
{
// Ok now lets make sure the "Type" value is there,
//and then do our bitwise operation on it.
if(ckey.GetValue("Type") != null)
{
ckey.SetValue("Type", ((int)ckey.GetValue("Type") | 256));
}
}
}