views:

241

answers:

3

I've got some old VB6 code part of which enumerates the running processes on the machine via a call to CreateToolhelpSnapshot. I'm attempting to run this code on Win 2003 R2 and I have reason to be a little suspicious of the list of processes that it's returning. I found this article which leads me to think I might need to use a different API call on 2003. However I cannot find the Microsoft KnowledgeBase article that he mentions. Or I can't find the English version anyway. I did find the article in German but I can't read German. I think it's advising me to use an API called EnumProcs but I don't find any such API in the Microsoft API docs (at least not at msdn.microsoft.com).

So, should I be using CreateToolhelpSnapshot on Win 2003 or is there some other API which I should use? And does anyone have any idea where I might find a copy of that KB article in English?

+2  A: 

This article gives quite a comprehensive listing of how to do what you need. It basically uses the EnumProcesses Windows API call instead of the GetActiveProcesses one.

Note that it's not just Windows Server 2003, but all the Windows versions of the NT family (XP, Vista, etc.) too.

Ant
In fact it's only NT. CreateToolhelp32Snapshot was added to 2000 and it's still in now. http://msdn.microsoft.com/en-us/library/ms682489(VS.85).aspx
MarkJ
I mean, nice link, and EnumProcesses is worth a try if CreateToolhelp32Snapshot doesn't return the results wanted. But CreateToolhelp32Snapshot does work on Windows Server 2003 according to the MSDN docs.
MarkJ
+2  A: 

Google Translate does an excellent job of translating that German KB page into English: HOW TO: Enumerate Applications Using Win32 APIs.

RichieHindle
You're right; I'm accustomed to the translations leaving something to be desired so I didn't even bother to try it.
Onorio Catenacci
+3  A: 
  • Your freevbcode.com article is a red herring from the bathroom wall of code. It says that CreateToolhelp32Snapshot only works on Windows 95, 98, and Me. This was true once - it wasn't in NT - but it's in Windows 2000 and all the later versions.
  • The MSDN page on CreateToolhelp32Snapshot remarks section suggests reasons why the call can fail. (It states it works on Windows Server 2003: "minimum supported server is Windows 2000 Server", and the API call has not been retired.)
  • If you can't get CreateToolhelpSnapshot to work, go with Ant's answer and use EnumProcesses. More information about this method: an old Microsoft Knowledge Base article on enumerating processes from VB6 suggests you use EnumProcesses. You will have to distribute PSAPI.DLL, but it is free with the Platform SDK. Another source on EnumProcesses is from the old but excellent book Hardcore Visual Basic, now available free online.
MarkJ
Didn't know it was still working with 2000 and up. Nice find.
Ant