I wrote this code primarily to be able to get the windows services running in each svchost.exe process, however it can be used against any process to see which services (if any) are running within it. It makes use of the EnumServicesStatusEx, OpenSCManager, and CloseServiceHandle Windows APIs. If you are not a developer and just want to see which services are in an svchost.exe process, see this post
Archives For vb.net
I recently needed to get the command line arguments that an external process was started with (one that was not started by my application, svchost.exe to be specific) and found that the only way I could get this information was with Windows APIs. The API in question just returned pointers that references locations in the memory of the external process (which meant I could not use the .NET Marshal methods as they would treat the pointers as references to my own process’s memory – thanks to wj32 for helping me understand that) so I had to use the Windows API ReadProcessMemory. I will be posting my full example of how to get the command line parameters for an external process soon but for now I thought I would just post this .NET class I wrote that makes reading process memory a bit easier as it does all of the API work for you.
Here’s yet another .NET wrapper/helper that I’ve written for some Windows API functionality. This time my code makes use of about 6 different Windows APIs to provide you with a method that will return a list of all windows that are currently open on the computer along with their handle, title bar text, class name and the process that owns the window.
Also might be worth mentioning: I’m going to be releasing a class library soon full of lots of these “.NET friendly” methods that I’ve written to make calling specific Windows APIs simpler and easier. So you can just add a reference to the class library DLL and then you can avoid having to use the APIs directly as you can just use my nice simple .NET methods, with no need to marshal anything across to unmanaged code. Check back on this blog soon if that sounds like something you would be interested in.
Perhaps this is common knowledge for a lot of people but even though I have been working with Windows APIs from VB.NET quite a lot recently, I did not know about this little ‘trick’ until today.