Changeset f22f5a9 in nscp for trunk/modules/CheckSystem/CheckSystem.cpp
- Timestamp:
- 04/28/05 20:17:32 (8 years ago)
- Children:
- 7b04f88
- Parents:
- ae192e3
- File:
-
- 1 edited
-
trunk/modules/CheckSystem/CheckSystem.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/CheckSystem/CheckSystem.cpp
rae192e3 rf22f5a9 7 7 #include <tlhelp32.h> 8 8 #include <EnumNtSrv.h> 9 #include <EnumProcess.h> 9 10 10 11 CheckSystem gNSClientCompat; … … 27 28 * @return 28 29 */ 29 CheckSystem::CheckSystem() {}30 CheckSystem::CheckSystem() : processMethod_(0) {} 30 31 /** 31 32 * Default d-tor … … 40 41 bool CheckSystem::loadModule() { 41 42 pdhThread.createThread(); 43 44 std::string wantedMethod = NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_ENUMPROC_METHOD, C_SYSTEM_ENUMPROC_METHOD_DEFAULT); 45 46 CEnumProcess tmp; 47 int method = tmp.GetAvailableMethods(); 48 49 if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_PSAPI) { 50 if (method == (method|ENUM_METHOD::PSAPI)) { 51 processMethod_ = ENUM_METHOD::PSAPI; 52 } else { 53 NSC_LOG_ERROR_STD("PSAPI method not avalible, check " C_SYSTEM_ENUMPROC_METHOD " option."); 54 } 55 } else { 56 if (method == (method|ENUM_METHOD::TOOLHELP)) { 57 processMethod_ = ENUM_METHOD::TOOLHELP; 58 } else { 59 NSC_LOG_ERROR_STD("TOOLHELP method not avalible, check " C_SYSTEM_ENUMPROC_METHOD " option."); 60 } 61 } 42 62 return true; 43 63 } … … 109 129 return checkCounter(command, argLen, char_args, msg, perf); 110 130 } 111 /*112 case REQ_PROCSTATE:113 rb = NSCommands::procState(arrayBuffer::arrayBuffer2list(argLen, char_args));114 msg = rb.msg_;115 perf = rb.perf_;116 return rb.code_;117 */118 131 return NSCAPI::returnIgnored; 119 132 } … … 390 403 * @return a hash_map with all running processes 391 404 */ 392 NSPROCLST GetProcessList(void) 393 { 394 HANDLE hProcessSnap; 395 PROCESSENTRY32 pe32; 405 NSPROCLST GetProcessList(int processMethod) 406 { 396 407 NSPROCLST ret; 397 398 // Take a snapshot of all processes in the system. 399 hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); 400 if( hProcessSnap == INVALID_HANDLE_VALUE ) 401 throw "CreateToolhelp32Snapshot (of processes) failed"; 402 403 // Set the size of the structure before using it. 404 pe32.dwSize = sizeof( PROCESSENTRY32 ); 405 406 // Retrieve information about the first process, 407 // and exit if unsuccessful 408 if( !Process32First( hProcessSnap, &pe32 ) ) { 409 CloseHandle( hProcessSnap ); // Must clean up the snapshot object! 410 throw "Process32First failed!"; 411 } 412 413 // Now walk the snapshot of processes, and 414 // display information about each process in turn 415 do { 416 ret[pe32.szExeFile] = pe32.th32ProcessID; 417 } while( Process32Next( hProcessSnap, &pe32 ) ); 418 419 // Don't forget to clean up the snapshot object! 420 CloseHandle( hProcessSnap ); 408 if (processMethod == 0) { 409 NSC_LOG_ERROR_STD("ProcessMethod not defined or not available."); 410 return ret; 411 } 412 CEnumProcess enumeration; 413 enumeration.SetMethod(processMethod); 414 CEnumProcess::CProcessEntry entry; 415 for (BOOL OK = enumeration.GetProcessFirst(&entry); OK; OK = enumeration.GetProcessNext(&entry) ) { 416 ret[entry.lpFilename] = entry.dwPID; 417 } 421 418 return ret; 422 419 } … … 452 449 NSPROCLST runningProcs; 453 450 try { 454 runningProcs = GetProcessList( );451 runningProcs = GetProcessList(processMethod_); 455 452 } catch (char *c) { 456 453 NSC_LOG_ERROR_STD("ERROR: " + c);
Note: See TracChangeset
for help on using the changeset viewer.








