Reliably detect 16 bit process
Due to the need to run a 15+ year old application I wish to create a watchdog program to ensure a 16 bit application is running on a 32 bit version of Windows XP Pro and start it if necessary. Normally I'd use EnumWindows() to look for the application's window. Unfortunately, this doesn't work, or at least not reliably, for 16 bit apps.
Given that I have absolutely no control over the code in the application开发者_如何学JAVA in question, how can I reliably detect whether or not it's running? I'm coding this in C (not C++ or C#).
You'll probably need to enumerate processes (e.g., EnumProcesses
with GetModuleFilenameEx
or CreateToolhelp32Snapshot
with Process32First
and Process32Next
). If you don't find an instance of ntvdm.exe
, then no 16-bit process is running, and you can stop there. If you do find an instance of ntvdm.exe
, you can use VDMEnumTaskWOWEx
to enumerate the 16-bit processes running in it.
Back when it was still under the original owners, I posted an article on CodeGuru demonstrating how to do all of this. It'd take a bit of work to make it compile under a modern compiler (e.g., it's old enough that it uses iostream.h
instead of iostream
, but the process enumeration part should still be pretty much right (though, looking at things, you'll also need to enable the SeDebugPrivilege
for it to work on Windows 7).
精彩评论