Index: installer/src/installer-lib/process.cpp |
=================================================================== |
--- a/installer/src/installer-lib/process.cpp |
+++ b/installer/src/installer-lib/process.cpp |
@@ -31,7 +31,11 @@ |
{ |
if ( handle == INVALID_HANDLE_VALUE ) |
{ |
- throw std::runtime_error( "Invalid handle" ) ; |
+ // TODO: This code really deserves use of a proper exception class that packages |
+ // Windows API errors consistently. |
+ char tmp[256]; |
+ sprintf_s(tmp, "Invalid handle. Last error: %d", GetLastError()); |
+ throw std::runtime_error( tmp ) ; |
} |
} |
@@ -47,12 +51,26 @@ |
return 0 == wcsncmpi( process.szExeFile, name, length ) ; |
} |
-//------------------------------------------------------- |
-// process_by_any_exe_name_CI |
-//------------------------------------------------------- |
-bool process_by_any_exe_name_CI::operator()( const PROCESSENTRY32W & process ) |
+ |
+bool process_by_any_exe_with_any_module::operator()( const PROCESSENTRY32W & process ) |
{ |
- return names.find( process.szExeFile ) != names.end() ; |
+ if (processNames.find(process.szExeFile) != processNames.end()) |
+ { |
+ if (moduleNames.empty()) |
+ return true; |
+ |
+ ModulesSnapshot ms(process.th32ProcessID); |
+ ModulesSnapshot::Pointer me = ms.begin(); |
+ while (me != ms.end()) |
+ { |
+ if (moduleNames.find(me->szModule) != moduleNames.end()) |
+ { |
+ return true; |
+ } |
+ me = ms.next(); |
+ } |
+ } |
+ return false; |
} |
//------------------------------------------------------- |
@@ -162,6 +180,26 @@ |
//------------------------------------------------------- |
+// ModulesSnapshot |
+//------------------------------------------------------- |
+ModulesSnapshot::ModulesSnapshot(DWORD processId) |
+ : handle(::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId)) |
+{ |
+ module.dwSize = sizeof(MODULEENTRY32); |
+} |
+ |
+MODULEENTRY32W * ModulesSnapshot::begin() |
+{ |
+ return ::Module32FirstW(handle, &module) ? (&module) : 0; |
+} |
+ |
+MODULEENTRY32W * ModulesSnapshot::next() |
+{ |
+ return ::Module32NextW(handle, &module) ? (&module) : 0; |
+} |
+ |
+ |
+//------------------------------------------------------- |
// send_message, send_endsession_messages |
//------------------------------------------------------- |
/** |