BOOL WINAPI QueryServiceConfig( __in SC_HANDLE hService, __out_opt LPQUERY_SERVICE_CONFIG lpServiceConfig, __in DWORD cbBufSize, __out LPDWORD pcbBytesNeeded );hService [in] A handle to the service. This handle is returned by the OpenService or CreateService function, and it must have the SERVICE_QUERY_CONFIG access right. For more information, see Service Security and Access Rights.lpServiceConfig [out, optional] A pointer to a buffer that receives the service configuration information. The format of the data is a QUERY_SERVICE_CONFIG structure.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] The size of the buffer pointed to by the lpServiceConfig parameter, in bytes.pcbBytesNeeded [out] A pointer to a variable that receives the number of bytes needed to store all the configuration information, if the function fails with ERROR_INSUFFICIENT_BUFFER. typedef struct _QUERY_SERVICE_CONFIG { DWORD dwServiceType; DWORD dwStartType; DWORD dwErrorControl; LPTSTR lpBinaryPathName; //看到没?这个 LPTSTR lpLoadOrderGroup; DWORD dwTagId; LPTSTR lpDependencies; LPTSTR lpServiceStartName; LPTSTR lpDisplayName; }QUERY_SERVICE_CONFIG, *LPQUERY_SERVICE_CONFIG;
打开服务管理器 找到你要获取PID的服务名
二
枚举这个数据结构 获取他的路径名称
三
字符串的修改 获取exe名称
四
OpenProcess打开这个exe进程 得到PID中间要判断是否服务已经运行 没运行就不用后续的动作了
四
OpenProcess打开这个exe进程 得到PID ------------
服务进程名称 不一定是服务EXE名称
BOOL WINAPI QueryServiceConfig(
__in SC_HANDLE hService,
__out_opt LPQUERY_SERVICE_CONFIG lpServiceConfig,
__in DWORD cbBufSize,
__out LPDWORD pcbBytesNeeded
);hService [in]
A handle to the service. This handle is returned by the OpenService or CreateService function, and it must have the SERVICE_QUERY_CONFIG access right. For more information, see Service Security and Access Rights.lpServiceConfig [out, optional]
A pointer to a buffer that receives the service configuration information. The format of the data is a QUERY_SERVICE_CONFIG structure.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]
The size of the buffer pointed to by the lpServiceConfig parameter, in bytes.pcbBytesNeeded [out]
A pointer to a variable that receives the number of bytes needed to store all the configuration information, if the function fails with ERROR_INSUFFICIENT_BUFFER.
typedef struct _QUERY_SERVICE_CONFIG {
DWORD dwServiceType;
DWORD dwStartType;
DWORD dwErrorControl;
LPTSTR lpBinaryPathName; //看到没?这个
LPTSTR lpLoadOrderGroup;
DWORD dwTagId;
LPTSTR lpDependencies;
LPTSTR lpServiceStartName;
LPTSTR lpDisplayName;
}QUERY_SERVICE_CONFIG, *LPQUERY_SERVICE_CONFIG;