Handler An application-defined callback function used with the RegisterServiceCtrlHandler function. HandlerEx RegisterServiceCtrlHandler 注冊一個(gè)函數(shù)處理控制碼請求。 RegisterServiceCtrlHandlerEx ServiceMain 服務(wù)程序入口函數(shù)。 SetServiceBits Registers a service type with the service control manager and the Server service. SetServiceStatus Updates the service control manager's status information for the calling service. StartServiceCtrlDispatcher Connects the main thread of a service PRocess to the service control manager.
下面的函數(shù)被用于管理和配置服務(wù)
函數(shù) 描述
ChangeServiceConfig 改變服務(wù)的開機(jī)運(yùn)行狀態(tài)。 ChangeServiceConfig2 改變服務(wù)的描述。 CloseServiceHandle 關(guān)閉服務(wù)句柄。 ControlService 在一個(gè)服務(wù)已經(jīng)被開啟的情況下,向這個(gè)服務(wù)發(fā)出控制碼。 ControlServiceEx CreateService 創(chuàng)建一個(gè)服務(wù)對象,并增加它到服務(wù)控制管理數(shù)據(jù)庫。 DeleteService 在服務(wù)控制管理數(shù)據(jù)庫中標(biāo)示要?jiǎng)h除的服務(wù)。 EnumDependentServices 獲取服務(wù)管理數(shù)據(jù)庫中所有服務(wù)的名稱和當(dāng)前狀態(tài)。 EnumServicesStatusEx GetServiceDisplayName 獲取服務(wù)的描述。 GetServiceKeyName Retrieves the service name of the specified service. NotifyBootConfigStatus Reports the boot status to the service control manager. NotifyServiceStatusChange Enables an application to receive notification when the specified service is created or
deleted or when its status changes. OpenSCManager 和指定機(jī)器的服務(wù)控制管理器建立連接并打開服務(wù)控制管理器數(shù)據(jù)庫。 OpenService 打開一個(gè)存在的服務(wù)。 QueryServiceConfig QueryServiceConfig2 QueryServiceObjectSecurity Retrieves a copy of the security descriptor associated with a service object. QueryServiceStatusEx 查詢服務(wù)程序現(xiàn)在的運(yùn)行狀態(tài)。 SetServiceObjectSecurity Sets the security descriptor of a service object. StartService 開啟一個(gè)服務(wù)。
void ReconfigureService(wchar_t * ServiceName, wchar_t * ServiceDisp) { SC_HANDLE schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (schSCManager != NULL) { // Need to acquire database lock before reconfiguring. SC_LOCK sclLock = LockServiceDatabase(schSCManager); if (sclLock != NULL) { // Open a handle to the service. SC_HANDLE schService = OpenService( schSCManager, // SCManager database ServiceName, // name of service SERVICE_CHANGE_CONFIG); // need CHANGE access