Left: | ||
Right: |
OLD | NEW |
---|---|
1 #include <stdexcept> | 1 #include <stdexcept> |
2 #include <functional> | 2 #include <functional> |
3 #include <wctype.h> | 3 #include <wctype.h> |
4 // <thread> is C++11, but implemented in VS2012 | 4 // <thread> is C++11, but implemented in VS2012 |
5 #include <thread> | 5 #include <thread> |
6 | 6 |
7 #include "installer-lib.h" | 7 #include "installer-lib.h" |
8 #include "process.h" | 8 #include "process.h" |
9 | 9 |
10 //------------------------------------------------------- | 10 //------------------------------------------------------- |
11 //------------------------------------------------------- | 11 //------------------------------------------------------- |
12 bool process_by_any_exe_with_any_module::operator()( const PROCESSENTRY32W & pro cess ) | 12 typedef int (__stdcall *IsImmersiveDynamicFunc)(HANDLE); |
13 bool process_by_any_exe_not_immersive::operator()( const PROCESSENTRY32W & proce ss ) | |
13 { | 14 { |
14 if (processNames.find(process.szExeFile) != processNames.end()) | 15 if (processNames.find(process.szExeFile) != processNames.end()) |
15 { | 16 { |
16 if (moduleNames.empty()) | 17 // Make sure the process is still alive |
17 return true; | 18 HANDLE procHandle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, process.th 32ProcessID); |
19 if ((procHandle == NULL) || (procHandle == INVALID_HANDLE_VALUE)) return fal se; | |
18 | 20 |
19 Module_Snapshot ms(process.th32ProcessID); | 21 DWORD exitCode; |
20 const MODULEENTRY32W* me = ms.first(); | 22 if (!GetExitCodeProcess(procHandle, &exitCode)) return false; |
21 while (me != 0) | 23 |
22 { | 24 if (exitCode != STILL_ACTIVE) return false; |
23 if (moduleNames.find(me->szModule) != moduleNames.end()) | 25 |
24 { | 26 // Check if this is a Windows Store app process (we don't care for IE in Mod ern UI) |
25 return true; | 27 HINSTANCE user32Dll = LoadLibrary(L"user32.dll"); |
Eric
2014/06/25 15:08:51
What's the reason for a dynamic load of this libra
Oleksandr
2014/06/26 13:25:57
Why make assumptions? From MSDN http://msdn.micros
| |
26 } | 28 if (!user32Dll) return true; |
27 me = ms.next(); | 29 |
28 } | 30 IsImmersiveDynamicFunc IsImmersiveDynamicCall = (IsImmersiveDynamicFunc)GetP rocAddress(user32Dll, "IsImmersiveProcess"); |
31 if (!IsImmersiveDynamicCall) return true; | |
32 | |
33 BOOL retValue = !IsImmersiveDynamicCall(procHandle); | |
Eric
2014/06/25 15:08:51
IsImmersiveDynamicCall commingles a false result w
Oleksandr
2014/06/26 13:25:57
I agree it wouldn't hurt to log the GetLastError h
| |
34 CloseHandle(procHandle); | |
Eric
2014/06/25 15:08:51
Resource Leak. CloseHandle() won't be called under
| |
35 | |
36 return retValue; | |
29 } | 37 } |
30 return false; | |
31 } | 38 } |
32 | 39 |
33 //------------------------------------------------------- | 40 //------------------------------------------------------- |
34 // creator_process | 41 // creator_process |
35 //------------------------------------------------------- | 42 //------------------------------------------------------- |
36 DWORD creator_process( HWND window ) | 43 DWORD creator_process( HWND window ) |
37 { | 44 { |
38 DWORD pid ; | 45 DWORD pid ; |
39 DWORD r = GetWindowThreadProcessId( window, & pid ) ; | 46 DWORD r = GetWindowThreadProcessId( window, & pid ) ; |
40 if ( r == 0 ) | 47 if ( r == 0 ) |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 * Send WM_ENDSESSION if all processes are ready to shut down. | 249 * Send WM_ENDSESSION if all processes are ready to shut down. |
243 * We try this technique first, since this allows an application to restore its application state when it starts up again. | 250 * We try this technique first, since this allows an application to restore its application state when it starts up again. |
244 */ | 251 */ |
245 { | 252 { |
246 endsession_accumulator acc ; | 253 endsession_accumulator acc ; |
247 send_message m1( WM_QUERYENDSESSION, 0, ENDSESSION_CLOSEAPP, acc ) ; | 254 send_message m1( WM_QUERYENDSESSION, 0, ENDSESSION_CLOSEAPP, acc ) ; |
248 iterate_our_windows( m1 ) ; | 255 iterate_our_windows( m1 ) ; |
249 | 256 |
250 if ( acc.permit_end_session ) | 257 if ( acc.permit_end_session ) |
251 { | 258 { |
252 send_message m2( WM_ENDSESSION, 0, 0 ) ; | 259 send_message m2( WM_ENDSESSION, 0, ENDSESSION_CLOSEAPP ) ; |
253 iterate_our_windows( m2 ) ; | 260 iterate_our_windows( m2 ) ; |
254 } | 261 } |
255 } | 262 } |
256 break ; | 263 break ; |
257 | 264 |
258 case 2 : | 265 case 2 : |
259 { | 266 { |
260 /* | 267 /* |
261 * Send WM_QUERYENDSESSION and WM_ENDSESSION to every admissible window s ingly, not accumulating results. | 268 * Send WM_QUERYENDSESSION and WM_ENDSESSION to every admissible window s ingly, not accumulating results. |
262 */ | 269 */ |
(...skipping 29 matching lines...) Expand all Loading... | |
292 if ( ! is_running() ) | 299 if ( ! is_running() ) |
293 { | 300 { |
294 return true ; | 301 return true ; |
295 } | 302 } |
296 } | 303 } |
297 // Assert is_running() | 304 // Assert is_running() |
298 } | 305 } |
299 // No control path leaves the for-loop. | 306 // No control path leaves the for-loop. |
300 } ; | 307 } ; |
301 | 308 |
OLD | NEW |