日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > windows客戶端開發--監測windows某一服務是否開啟

windows客戶端開發--監測windows某一服務是否開啟

來源:程序員人生   發布時間:2016-07-08 15:46:17 閱讀次數:2603次

windows api

OpenSCManager
function OpenSCManager(
lpMachineName: PChar,
lpDatabaseName: PChar,
dwDesiredAccess: DWORD): SC_HANDLE; stdcall;
參數
lpMachineName
指向零終止字符串,指定目標計算機的名稱。如果該指針為NULL ,或它指向1個空字符串,那末該函數連接到本地計算機上的服務控制管理器。
lpDatabaseName
指向零終止字符串,指定將要打開的服務控制管理數據庫的名稱。此字符串應被置
為 SERVICES_ACTIVE_DATABASE。如果該指針為NULL ,則打開默許的 SERVICES_ACTIVE_DATABASE
數據庫
dwDesiredAccess
指定服務訪問控制管理器的權限。在授與要求的權限前,系統會檢查調用進程的權限令牌,該令牌針對與服
務控制管理器相干的安全描寫符的權限控制列表。另外,該函數的調用將隱式地指定
SC_MANAGER_CONNECT 的訪問權限。
另外,以下服務控制管理器對象的訪問類型可以被指定:
SC_MANAGER_ALL_ACCESS 除所有此表中列出的訪問類型,還包括
STANDARD_RIGHTS_REQUIRED。
SC_MANAGER_CONNECT 可以連接到服務控制管理器。
SC_MANAGER_CREATE_SERVICE 使要求的CreateService函數創建1個服務對象,并將其添加到數
據庫中。
SC_MANAGER_ENUMERATE_SERVICE 使要求的EnumServicesStatus功能清單的服務,這是在數據庫
中。
SC_MANAGER_LOCK 使要求的LockServiceDatabase功能取得鎖定數據庫
SC_MANAGER_QUERY_LOCK_STATUS 使要求的QueryServiceLockStatus檢索功能鎖定狀態信息的數據
庫。

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

Parameters
hSCManager [in]
A handle to the service control manager database. The OpenSCManager function returns this handle. For more information, see Service Security and Access Rights.
lpServiceName [in]
The name of the service to be opened. This is the name specified by the lpServiceName parameter of the CreateService function when the service object was created, not the service display name that is shown by user interface applications to identify the service.
The maximum string length is 256 characters. The service control manager database preserves the case of the characters, but service name comparisons are always case insensitive. Forward-slash (/) and backslash () are invalid service name characters.
dwDesiredAccess [in]
The access to the service. For a list of access rights, see Service Security and Access Rights.
Before granting the requested access, the system checks the access token of the calling process against the discretionary access-control list of the security descriptor associated with the service object.
Return value
If the function succeeds, the return value is a handle to the service.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
The following error codes can be set by the service control manager. Others can be set by the registry functions that are called by the service control manager.

QueryServiceStatusEx
BOOL WINAPI QueryServiceStatusEx(
In SC_HANDLE hService,
In SC_STATUS_TYPE InfoLevel,
Out_opt LPBYTE lpBuffer,
In DWORD cbBufSize,
Out LPDWORD pcbBytesNeeded
);

Parameters
hService
[in] Handle to the service. This handle is returned by the CreateService or OpenService function, and it must have the SERIVCE_QUERY_STATUS access right. For more information, see Service Security and Access Rights.
InfoLevel
[in] Service attributes to be returned. Use SC_STATUS_PROCESS_INFO to retrieve the service status information. The lpBuffer parameter is a pointer to a SERVICE_STATUS_PROCESS structure.
Currently, no other information levels are defined.

lpBuffer
[out] Pointer to the buffer that receives the status information. The format of this data depends on the value of the InfoLevel parameter.
The maximum size of this array is 8K bytes. To determine the required size, specify NULL for this parameter and 0 for the cbBufSize parameter. The function will fail and GetLastError will return ERROR_INSUFFICIENT_BUFFER. The pcbBytesNeeded parameter will receive the required size.

cbBufSize
[in] Size of the buffer pointed to by the lpBuffer parameter, in bytes.
pcbBytesNeeded
[out] Pointer to a variable that receives the number of bytes needed to store all status information, if the function fails with ERROR_INSUFFICIENT_BUFFER.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. The following errors can be returned.

上面這3個API是我們用到的,msdn上都有描寫,我們應當玩點實在的。

首先明確不要把官方的start service例子所迷惑。

注意1

SC_HANDLE serviceDbHandle = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS)

返回空,毛病為0。毛病的緣由就是,你當前不是管理員賬戶,所以不能使用SC_MANAGER_ALL_ACCESS,我們應當這樣修改:

SC_HANDLE serviceDbHandle = OpenSCManager(NULL,NULL,SC_MANAGER_ENUMERATE_SERVICE|GENERIC_READ );

注意2

schService = OpenService(schSCManager, szSvcName, SERVICE_ALL_ACCESS);

也是返回的0,緣由跟上面1樣,因而這樣修改:

SC_HANDLE serviceHandle = OpenService(serviceDbHandle, szSvcName, SERVICE_QUERY_STATUS);

注意3
如果不是管理員賬戶,不要試圖使用程序開啟和停止某1個服務。

查詢

SERVICE_STATUS_PROCESS status; DWORD bytesNeeded; if(QueryServiceStatusEx(serviceHandle, SC_STATUS_PROCESS_INFO,(LPBYTE) &status,sizeof(SERVICE_STATUS_PROCESS), &bytesNeeded) == NULL) { //QueryServiceStatusEx failed } if (status.dwCurrentState == SERVICE_RUNNING) { } else if(status.dwCurrentState == SERVICE_STOPPED) { }
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 国产欧美精品一区二区三区四区 | 污视频免费在线看 | 日韩精品在线电影 | 黄色免费在线视频 | 国产白浆在线观看 | 精品国产一区二区三区不卡蜜臂 | 国产精品麻豆视频 | a级毛片观看 | 久久久7| 日韩免费中文字幕 | 成人免费黄网站 | 久久视频在线看 | 一区二区三区中文字幕 | 免费99视频 | 亚洲高清在线观看 | 亚洲乱码一区二区三区在线观看 | 亚洲免费婷婷 | 日韩综合在线 | 911影院在线观看网站 | 亚洲精品美女久久久久99 | 亚洲电影免费观看 | 久久精品国产免费 | 在线观看日韩av | 国产二区精品 | 国产性av| 色婷婷综合久久久久中文一区二区 | 黄色一级大片在线免费看产 | 国产一区二区视频在线 | 青青草天堂 | 欧美日韩国产在线一区 | 欧美精品一区二区三区四区五区 | 日本欧美国产 | 成人黄色大片免费看 | 欧美日韩在线看 | 日韩电影av| 久久精品免费看 | 精品国产黄a∨片高清在线 五月色综合 | 人成在线 | 黑人网站 | 一区二区日韩精品 | 久久免费精品 |