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 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.,
EnumProcesseswithGetModuleFilenameExorCreateToolhelp32SnapshotwithProcess32FirstandProcess32Next). If you don’t find an instance ofntvdm.exe, then no 16-bit process is running, and you can stop there. If you do find an instance ofntvdm.exe, you can useVDMEnumTaskWOWExto 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.hinstead ofiostream, but the process enumeration part should still be pretty much right (though, looking at things, you’ll also need to enable theSeDebugPrivilegefor it to work on Windows 7).