| 14 | | if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) { |
| 15 | | for (unsigned int i=0; i<cbNeeded/sizeof(HMODULE); i++) { |
| 16 | | TCHAR szModName[MAX_PATH]; |
| | 13 | // Determine the required buffer size for the data. |
| | 14 | pdhStatus = PdhEnumObjectItems ( |
| | 15 | NULL, // real time source |
| | 16 | NULL, // local machine |
| | 17 | TEXT("Thread"), // object to enumerate |
| | 18 | szCounterListBuffer, // pass NULL and 0 |
| | 19 | &dwCounterListSize, // to get length required |
| | 20 | szInstanceListBuffer, // buffer size |
| | 21 | &dwInstanceListSize, // |
| | 22 | PERF_DETAIL_WIZARD, // counter detail level |
| | 23 | 0); |
| 18 | | if (GetModuleBaseName( |
| 19 | | hProcess, hMods[i], szModName, sizeof(szModName)/sizeof(TCHAR) |
| 20 | | )) { |
| 21 | | if (0==_wcsicmp(szModName, _T("npswf32.dll"))) { |
| 22 | | CloseHandle(hProcess); |
| 23 | | return 1; |
| 24 | | } |
| 25 | | } |
| 26 | | } |
| 27 | | } |
| | 25 | if (pdhStatus == PDH_MORE_DATA) |
| | 26 | { |
| | 27 | // Allocate the buffers and try the call again. |
| | 28 | szCounterListBuffer = (LPTSTR)malloc ( |
| | 29 | (dwCounterListSize * sizeof (TCHAR))); |
| | 30 | szInstanceListBuffer = (LPTSTR)malloc ( |
| | 31 | (dwInstanceListSize * sizeof (TCHAR))); |
| 29 | | CloseHandle(hProcess); |
| 30 | | return 0; |
| | 33 | if ((szCounterListBuffer != NULL) && |
| | 34 | (szInstanceListBuffer != NULL)) |
| | 35 | { |
| | 36 | pdhStatus = PdhEnumObjectItems ( |
| | 37 | NULL, // real time source |
| | 38 | NULL, // local machine |
| | 39 | TEXT("Thread"), // object to enumerate |
| | 40 | szCounterListBuffer, // buffer to receive counter list |
| | 41 | &dwCounterListSize, |
| | 42 | szInstanceListBuffer, // buffer to receive instance list |
| | 43 | &dwInstanceListSize, |
| | 44 | PERF_DETAIL_WIZARD, // counter detail level |
| | 45 | 0); |
| | 46 | |
| | 47 | if (pdhStatus == ERROR_SUCCESS) |
| | 48 | { |
| | 49 | _tprintf (TEXT("\nEnumerating Processes:")); |
| | 50 | |
| | 51 | // Walk the instance list. The list can contain one |
| | 52 | // or more null-terminated strings. The last string |
| | 53 | // is followed by a second null-terminator. |
| | 54 | for (szThisInstance = szInstanceListBuffer; |
| | 55 | *szThisInstance != 0; |
| | 56 | szThisInstance += lstrlen(szThisInstance) + 1) |
| | 57 | { |
| | 58 | _tprintf (TEXT("\n %s"), szThisInstance); |
| | 59 | } |
| | 60 | } |
| | 61 | else |
| | 62 | { |
| | 63 | _tprintf(TEXT("\nPdhEnumObjectItems failed with %ld."), pdhStatus); |
| | 64 | } |
| | 65 | } |
| | 66 | else |
| | 67 | { |
| | 68 | _tprintf (TEXT("\nUnable to allocate buffers")); |
| | 69 | pdhStatus = ERROR_OUTOFMEMORY; |
| | 70 | } |
| | 71 | |
| | 72 | if (szCounterListBuffer != NULL) |
| | 73 | free (szCounterListBuffer); |
| | 74 | |
| | 75 | if (szInstanceListBuffer != NULL) |
| | 76 | free (szInstanceListBuffer); |
| | 77 | } |
| | 78 | else |
| | 79 | { |
| | 80 | _tprintf(TEXT("\nPdhEnumObjectItems failed with %ld."), pdhStatus); |
| | 81 | } |
| | 82 | |
| | 83 | _getch(); |
| | 84 | return pdhStatus; |
| 32 | | |
| 33 | | bool FindFlash() { |
| 34 | | DWORD aProcesses[1024], cbNeeded; |
| 35 | | |
| 36 | | // Get the list of process identifiers. |
| 37 | | if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded)) { |
| 38 | | return 0; |
| 39 | | } |
| 40 | | |
| 41 | | // Calculate how many process identifiers were returned. |
| 42 | | DWORD cProcesses=cbNeeded/sizeof(DWORD); |
| 43 | | |
| 44 | | for (unsigned int i=0; i<cProcesses; i++) { |
| 45 | | if (ScanModules(aProcesses[i])) return 1; |
| 46 | | } |
| 47 | | |
| 48 | | return 0; |
| 49 | | } |
| 50 | | |
| 51 | | void _tmain() { |
| 52 | | printf("Found flash? %s\n", FindFlash()?"Yes":"No"); |
| 53 | | _getch(); |
| 54 | | } |