add util to extract exe from QUERY_SERVICE_CONFIG.lpBinaryPathName

This commit is contained in:
Doug MacEachern 2008-03-27 00:08:29 +00:00
parent b83b819b00
commit af661d2b7d
2 changed files with 38 additions and 0 deletions

View File

@ -604,6 +604,8 @@ int sigar_services_query(char *ptql,
sigar_ptql_error_t *error, sigar_ptql_error_t *error,
sigar_services_walker_t *walker); sigar_services_walker_t *walker);
char *sigar_service_exe_get(char *path, char *buffer, int basename);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -3466,3 +3466,39 @@ void sigar_services_status_close(sigar_services_status_t *ss)
} }
SIGAR_ZERO(ss); SIGAR_ZERO(ss);
} }
/* extract exe from QUERY_SERVICE_CONFIG.lpBinaryPathName
* leaves behind command-line arguments and quotes (if any)
*/
char *sigar_service_exe_get(char *path, char *buffer, int basename)
{
char *ptr;
strncpy(buffer, path, SIGAR_CMDLINE_MAX);
path = buffer;
if (*path == '"') {
++path;
if ((ptr = strchr(path, '"'))) {
*ptr = '\0';
}
}
else {
ptr = sigar_strcasestr(path, ".exe");
if (ptr) {
*(ptr+4) = '\0';
}
else {
if ((ptr = strchr(path, ' '))) {
*ptr = '\0';
}
}
}
if (basename && (ptr = strrchr(path, '\\'))) {
path = ++ptr;
}
return path;
}