Changeset 30065 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Jun 7, 2010 12:37:37 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/process-win.cpp
r30013 r30065 328 328 329 329 330 static BOOL rtProcFindProcessByName(const char * pszName, PSID pSID, PHANDLE phToken)331 { 332 AssertPtr(p szName);330 static BOOL rtProcFindProcessByName(const char * const *papszNames, PSID pSID, PHANDLE phToken) 331 { 332 AssertPtr(papszNames); 333 333 AssertPtr(pSID); 334 334 AssertPtr(phToken); … … 360 360 if (hSnap != INVALID_HANDLE_VALUE) 361 361 { 362 PROCESSENTRY32 procEntry; 363 procEntry.dwSize = sizeof(PROCESSENTRY32); 364 if (pfnProcess32First(hSnap, &procEntry)) 362 for (size_t i = 0; papszNames[i] && !fFound; i++) 365 363 { 366 do 367 { 368 if ( _stricmp(procEntry.szExeFile, pszName) == 0 369 && RT_SUCCESS(rtProcGetProcessHandle(procEntry.th32ProcessID, pSID, phToken))) 364 PROCESSENTRY32 procEntry; 365 procEntry.dwSize = sizeof(PROCESSENTRY32); 366 if (pfnProcess32First(hSnap, &procEntry)) 367 { 368 do 370 369 { 371 fFound = TRUE; 372 } 373 } while (pfnProcess32Next(hSnap, &procEntry) && !fFound); 370 if ( _stricmp(procEntry.szExeFile, papszNames[i]) == 0 371 && RT_SUCCESS(rtProcGetProcessHandle(procEntry.th32ProcessID, pSID, phToken))) 372 { 373 fFound = TRUE; 374 } 375 } while (pfnProcess32Next(hSnap, &procEntry) && !fFound); 376 } 377 else /* Process32First */ 378 dwErr = GetLastError(); 379 if (FAILED(dwErr)) 380 break; 374 381 } 375 else /* Process32First */376 dwErr = GetLastError();377 382 CloseHandle(hSnap); 378 383 } 379 else /* hSnap = !INVALID_HANDLE_VALUE */384 else /* hSnap == INVALID_HANDLE_VALUE */ 380 385 dwErr = GetLastError(); 381 386 } … … 406 411 if (pfnEnumProcesses(dwPIDs, sizeof(dwPIDs), &cbBytes)) 407 412 { 408 for ( DWORD dwIdx = 0; dwIdx < cbBytes/sizeof(DWORD) && !fFound; dwIdx++)413 for (size_t i = 0; papszNames[i] && !fFound; i++) 409 414 { 410 HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 411 FALSE, dwPIDs[dwIdx]); 412 if (hProc) 415 for (DWORD dwIdx = 0; dwIdx < cbBytes/sizeof(DWORD) && !fFound; dwIdx++) 413 416 { 414 char *pszProcName = NULL;415 DWORD dwSize = 128;416 do417 HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 418 FALSE, dwPIDs[dwIdx]); 419 if (hProc) 417 420 { 418 RTMemRealloc(pszProcName, dwSize); 419 if (pfnGetModuleBaseName(hProc, 0, pszProcName, dwSize) == dwSize) 420 dwSize += 128; 421 } while (GetLastError() == ERROR_INSUFFICIENT_BUFFER); 422 423 if (pszProcName) 424 { 425 if ( _stricmp(pszProcName, pszName) == 0 426 && RT_SUCCESS(rtProcGetProcessHandle(dwPIDs[dwIdx], pSID, phToken))) 421 char *pszProcName = NULL; 422 DWORD dwSize = 128; 423 do 427 424 { 428 fFound = TRUE; 425 RTMemRealloc(pszProcName, dwSize); 426 if (pfnGetModuleBaseName(hProc, 0, pszProcName, dwSize) == dwSize) 427 dwSize += 128; 428 if (dwSize > _4K) /* Play safe. */ 429 break; 430 } while (GetLastError() == ERROR_INSUFFICIENT_BUFFER); 431 432 if (pszProcName) 433 { 434 if ( _stricmp(pszProcName, papszNames[i]) == 0 435 && RT_SUCCESS(rtProcGetProcessHandle(dwPIDs[dwIdx], pSID, phToken))) 436 { 437 fFound = TRUE; 438 } 429 439 } 440 if (pszProcName) 441 RTStrFree(pszProcName); 442 CloseHandle(hProc); 430 443 } 431 if (pszProcName)432 RTStrFree(pszProcName);433 CloseHandle(hProc);434 444 } 435 445 } … … 587 597 && IsValidSid(pSID)) 588 598 { 589 fFound = rtProcFindProcessByName( 599 /* Array of process names we want to look for. */ 600 char *papszProcNames[] = 590 601 #ifdef VBOX 591 "VBoxTray.exe", 602 /* 603 * Add lookup for "explorer.exe" as a fallback in case the VBox 604 * Guest Additions are not (yet) installed, but prefer looking 605 * up "VBoxTray.exe" in the first place. 606 */ 607 { { "VBoxTray.exe" }, 608 { "explorer.exe" }, 609 NULL 610 }; 592 611 #else 593 "explorer.exe" 594 #endif 612 { { "explorer.exe" }, 613 NULL 614 }; 615 #endif 616 fFound = rtProcFindProcessByName(papszProcNames, 595 617 pSID, &hTokenUserDesktop); 596 618 }
Note:
See TracChangeset
for help on using the changeset viewer.