程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 用VS2003部署,讓服務程序安裝完後立即啟動服務並且選中“允許服務與桌面交互”及添加服務描述的方法

用VS2003部署,讓服務程序安裝完後立即啟動服務並且選中“允許服務與桌面交互”及添加服務描述的方法

編輯:.NET實例教程
-----------立即啟動--------------
private   void   serviceInstaller1_AfterInstall(object   sender,   System.Configuration.Install.InstallEventArgs   e)
{
ServiceController   myService   =   new   ServiceController( "XJOAPigeonholeServer ");
myService.Start();
myService.Dispose();
}


添加描述:1.1沒有直接方法,2.0裡有直接的方法   ServiceInstaller.Description
//----------------------------添加服務描述信息   開始   ------------
public   override   void   Install(IDictionary   stateServer)
{
Microsoft.Win32.RegistryKey   system,
//HKEY_LOCAL_MacHINE\Services\CurrentControlSet
currentControlSet,
//...\Services
services,
//...\ <Service   Name>
service,
//...\Parameters   -   this   is   where   you   can   put   service-specific   configuration
config;  
try
{
//Let   the   project   installer   do   its   job
base.Install(stateServer);

//Open   the   HKEY_LOCAL_MacHINE\SYSTEM   key
system   =   Microsoft.Win32.Registry.LocalMachine.OpenSubKey( "System ");
//Open   CurrentControlSet
currentControlSet   =   system.OpenSubKey( "CurrentControlSet ");
//Go   to   the   services   key
services   =   currentControlSet.OpenSubKey( "Services ");
//Open   the   key   for   your   service,   and   allow   writing
service   =   services.OpenSubKey(this.serviceInstaller1.ServiceName,   true);
//Add   your   service ''s   description   as   a   REG_SZ   value   named   "Description "
service.SetValue( "Description ", "XJOA系統自動歸檔服務(BeijiOffice) ");
//(Optional)   Add   some   custom   information   your   service   will   use...
//允許服務與桌面交互
service.SetValue( "Type ",0x00000110);
config   =   service.CreateSub
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved