c安装卸载服务代码.doc
文本预览下载声明
C#安装卸载服务的类
using System;
using System.Runtime.InteropServices;
namespace EAE.MyServiceInstaller class ServiceInstaller #region Private Variables
private string _servicePath;
private string _serviceName;
private string _serviceDisplayName;
#endregion Private Variables
#region DLLImport
[DllImport advapi32.dll ]
public static extern IntPtr OpenSCManager string lpMachineName,string lpSCDB, int scParameter ;
[DllImport Advapi32.dll ]
public static extern IntPtr CreateService IntPtr SC_HANDLE,string lpSvcName,string lpDisplayName, int dwDesiredAccess,int dwServiceType,int dwStartType,int dwErrorControl,string lpPathName, string lpLoadOrderGroup,int lpdwTagId,string lpDependencies,string lpServiceStartName,string lpPassword ;
[DllImport advapi32.dll ]
public static extern void CloseServiceHandle IntPtr SCHANDLE ;
[DllImport advapi32.dll ]
public static extern int StartService IntPtr SVHANDLE,int dwNumServiceArgs,string lpServiceArgVectors ;
[DllImport advapi32.dll,SetLastError true ]
public static extern IntPtr OpenService IntPtr SCHANDLE,string lpSvcName,int dwNumServiceArgs ;
[DllImport advapi32.dll ]
public static extern int DeleteService IntPtr SVHANDLE ;
[DllImport kernel32.dll ]
public static extern int GetLastError ;
#endregion DLLImport
// ///
// /// 应用程序入口.
// ///
//
// [STAThread]
// static void Main string[] args
// //
// string svcPath;
// string svcName;
// string svcDispName;
// //服务程序的路径
// svcPath @d:\service\EAEWS.exe;
// svcDispName myEAEWS;
// svcName myEAEWS;
// ServiceInstaller c new ServiceInstaller ;
// c.InstallService svcPath, svcName, svcDispName ;
// Console.Read ;
//
// /// /// 安装和运行
/// /// 程序路径.
/// 服务名
/// 服务显示名称.
/// 服务安装是否成功.
public bool InstallService string svcPath, string svcName, string svcDispName #region Constants declaration. int SC_MANAGER_CREATE_SERVICE 0x0002; int SERVICE_WIN32_OWN_PROCESS 0 //int SERVICE_DEMAND_START 0
显示全部