EnumProcesss
-
I am trying to enumerate through all the process on running on my computer so I can run through them and get a handle to the process using OpenProcess() const DWORD dProcessCountGuesstimate = 200; DWORD ardProcessIds[dProcessCountGuesstimate]; DWORD dNumberOfProccessFound = 0; BOOL bReturn; bReturn = EnumProcesses(ardProcessIds, dProcessCountGuesstimate * sizeof(DWORD), &dNumberOfProccessFound); My question: Is there a better way other then guessing the number of process running on my computer. It kinda seems retarded to do it this way. Could someone please help. Thanks.
-
I am trying to enumerate through all the process on running on my computer so I can run through them and get a handle to the process using OpenProcess() const DWORD dProcessCountGuesstimate = 200; DWORD ardProcessIds[dProcessCountGuesstimate]; DWORD dNumberOfProccessFound = 0; BOOL bReturn; bReturn = EnumProcesses(ardProcessIds, dProcessCountGuesstimate * sizeof(DWORD), &dNumberOfProccessFound); My question: Is there a better way other then guessing the number of process running on my computer. It kinda seems retarded to do it this way. Could someone please help. Thanks.
The problem is that the process set is very volatile. Processes get started and stopped very regularly, without user intervention. Even if you could determine immediately prior to calling EnumProcesses how many there were, there's no reason to believe the count will be the same by the time EnumProcesses executes. So, just make a wild-ass overestimate of the count, and hope for the best. I'm sure that with statistical analysis, you could determine a value that has a 99.99% probability of being sufficient. But memory is cheap, right? Make your best guess at how many there will be -- and double that. Even if you allow for 1000 processes, that's just 4000 bytes. Scot Brennecke Software Developer VC++ MVP