To know process(task) type


I can list all processes that currently active using process32first() and process32next() from ToolHelp32 unit but I can't determine process type, i.e. 16-bit or 32-bit.
How to know a process type? Thank you for your help.

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

MadshiConnect With a Mentor Commented:
Hi guys,

here comes the solution:

type TExeType = (etUnknown, etDos, etWin16, etConsole, etWin32);
function ExeType (exefile: string) : TExeType;
// Determines the type of the executable.

function ExeType(exefile: string) : TExeType;
var c1  : cardinal;
    sfi : TSHFileInfo;
    s1  : string;
  s1:=chr(c1 and $ff)+chr((c1 and $ff00) shr 8);
  if       s1='MZ'                                                           then result:=etDos
  else if  s1='NE'                                                           then result:=etWin16
  else if (s1='PE') and (hiWord(c1)=0)                                       then result:=etConsole
  else if (s1='PE') and (hiWord(c1)>0)                                       then result:=etWin32
  else if IsTextEqual(upStr(ExtractFileName(exefile)),upStr('winoa386.mod')) then result:=etDos
  else                                                                            result:=etUnknown;

Regards, Madshi.

I think they are all 32 bit. Eg: The dos boxes are 32 bit applications implementing a 16 bit process space for the DOS apps...


there are some DOS programs that you can run in Windows too, if they don't hang up your system ;)
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

one way I can think of is to find the main process handle, and from there find the path to the file which has executed the program... then you can use a function to determine whether or not this is a DOS or a WINDOWS program... Alex, has got a great example for doing just that (determining the type of program) on his website at

also check his website at

Good Luck!!

Hello Madshi :))

In fact, Alex's code does exactly that and kinda looks similar.. take a look at it... the real problem is that it is a PROCESS that is currently RUNNING, and you need to get the main process if you have a child process, and from there somehow find the name of the exe, and it is THEN when you use the code I/you suggested... I would say FindExecutable() might help a little in finding the executable...


Hi Viktor,

no, you don't have to look at child/parent processes. In win32 there are no child/parent processes. You can ask which process was started by which process. But it's no real parent/child relationship. Each process is completely on its own.
And why calling FindExecutable? I don't get it.
Cah said, he was using the toolhelp functions. The toolhelp functions give you the full executable path. You can DIRECTLY give it into my function. No problem that it is currently running. I'm doing this all the time...
And you don't need a process handle, either.

Alex code is a bit different. He doesn't use SHGetFileInfo. But why? SHGetFileInfo does a good job, and it works with currently running processes, too. Perhaps you get problems with checking running processes, if you use *HIS* code...  :-))

Regards, Madshi.
HencahAuthor Commented:
HI Madshi

I accept your answer, Big thanks

All Courses

From novice to tech pro — start learning today.