From 8c1608bb7698f5abb54c4f1ca0b8f0a2370722a0 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 5 Aug 2009 15:08:43 -0700 Subject: [PATCH] add wmi proc_exe wrapper --- src/os/win32/wmi.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/os/win32/wmi.cpp b/src/os/win32/wmi.cpp index a61737a9..d98df536 100644 --- a/src/os/win32/wmi.cpp +++ b/src/os/win32/wmi.cpp @@ -192,3 +192,33 @@ extern "C" int sigar_proc_args_wmi_get(sigar_t *sigar, sigar_pid_t pid, return status; } + +extern "C" int sigar_proc_exe_wmi_get(sigar_t *sigar, sigar_pid_t pid, + sigar_proc_exe_t *procexe) +{ + int status; + TCHAR buf[MAX_PATH+1]; + WMI *wmi = new WMI(); + + if (FAILED(wmi->Open())) { + return GetLastError(); + } + + procexe->name[0] = '\0'; + + if (FAILED(wmi->GetProcExecutablePath(pid, buf))) { + status = GetLastError(); + } + else { + status = SIGAR_OK; + /* SIGAR_W2A(buf, procexe->name, sizeof(procexe->name)); */ + WideCharToMultiByte(CP_ACP, 0, buf, -1, + (LPSTR)procexe->name, sizeof(procexe->name), + NULL, NULL); + } + + wmi->Close(); + delete wmi; + + return status; +}