Use QueryFullProcessImageName() if available.
[nssm.git] / process.cpp
index dc99597..e78283c 100644 (file)
@@ -411,7 +411,18 @@ int print_process(nssm_service_t *service, kill_t *k) {
       buffer[i] = _T('\0');\r
     }\r
   }\r
-  if (! GetModuleFileNameEx(k->process_handle, NULL, exe, _countof(exe))) _sntprintf_s(exe, _countof(exe), _TRUNCATE, _T("???"));\r
+\r
+  unsigned long size = _countof(exe);\r
+  if (! imports.QueryFullProcessImageName || ! imports.QueryFullProcessImageName(k->process_handle, 0, exe, &size)) {\r
+    /*\r
+      Fall back to GetModuleFileNameEx(), which won't work for WOW64 processes.\r
+    */\r
+    if (! GetModuleFileNameEx(k->process_handle, NULL, exe, _countof(exe))) {\r
+      long error = GetLastError();\r
+      if (error == ERROR_PARTIAL_COPY) _sntprintf_s(exe, _countof(exe), _TRUNCATE, _T("[WOW64]"));\r
+      else _sntprintf_s(exe, _countof(exe), _TRUNCATE, _T("???"));\r
+    }\r
+  }\r
 \r
   _tprintf(_T("% 8lu %s%s\n"), k->pid, buffer ? buffer : _T(""), exe);\r
 \r