服務管理器 小結

寫了兩天 終於把這個服務管理工具給寫好了,這也算是我的一個VC程序了。

現在發現其實一般的用VC沒什麼難的,只不過這個適應的過程有點長,比用.NET長好多啊,之前已經包裝過一個視頻卡的程序了。

呵呵,看來是適應了,不過要深入,還是有一段很長的路的要走,比如要適應多線程,還有能夠很流暢的寫網絡程序,這些東西,都還只是一點皮毛而已,而且我對Windows的理解也是不夠的,慢慢來吧。

 

剛剛 看了全運會的110欄,劉翔冠軍,這個冠軍的背後的汗水和痛苦也只有他自己知道,我們看到只有鮮花和掌聲。

 

 

總結一下,這個程序。

這個程序主要是瘋狂的使用幾個API,

1,在任何對服務的操作之前都要首先 打開服務管理器 OpenSCManager

SC_HANDLE OpenSCManager(LPCTSTR lpMachineName,LPCTSTR lpDatabaseName,DWORD dwDesiredAccess );

 

The OpenSCManager function establishes a connection to the service control manager on the specified computer and opens the specified service control manager database.

 

2,然後打開某個服務在對其進行操作 OpenService

SC_HANDLE OpenService(SC_HANDLE hSCManager,LPCTSTR lpServiceName,DWORD dwDesiredAccess);

The OpenService function opens an existing service.

 

3,關閉服務

CloseServiceHandle

 

4,獲取服務信息

BOOL EnumServicesStatus(
  SC_HANDLE hSCManager,
  DWORD dwServiceType,
  DWORD dwServiceState,
  LPENUM_SERVICE_STATUS lpServices,
  DWORD cbBufSize,
  LPDWORD pcbBytesNeeded,
  LPDWORD lpServicesReturned,
  LPDWORD lpResumeHandle
);

The EnumServicesStatus function enumerates services in the specified service control manager database. The name and status of each service are provided.

This function has been superseded by the EnumServicesStatusEx function. It returns the same information EnumServicesStatus returns, plus the process identifier and additional information for the service. In addition, EnumServicesStatusEx enables you to enumerate services that belong to a specified group.

 

5,查詢指定的服務的信息

BOOL QueryServiceConfig(
  SC_HANDLE hService,
  LPQUERY_SERVICE_CONFIG lpServiceConfig,
  DWORD cbBufSize,
  LPDWORD pcbBytesNeeded
);

The QueryServiceConfig function retrieves the configuration parameters of the specified service. Optional configuration parameters are available using the QueryServiceConfig2 function.

服務的附加信息由QueryServiceConfig2 獲取,比如服務的描述信息

 

6,開啓服務

BOOL StartService(
  SC_HANDLE hService,
  DWORD dwNumServiceArgs,
  LPCTSTR* lpServiceArgVectors
);

7,控制服務

這個可以控制服務的當前狀態,啓動方式等一些信息

BOOL StartService(
  SC_HANDLE hService,
  DWORD dwNumServiceArgs,
  LPCTSTR* lpServiceArgVectors
);

大概就是這個樣子了。

剩下的就是一下MFC的東西了

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章