To know process(task) type

Hi,

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.

Regards,
Cah
LVL 3
HencahAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
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...

Cheers,

Raymond.
0
viktornetCommented:
there are some DOS programs that you can run in Windows too, if they don't hang up your system ;)
0
viktornetCommented:
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 http://www.bhnet.com.br/~simonet/tipstricks/typeofexe.htm

also check his website at http://www.bhnet.com.br/~simonet/

Good Luck!!

..-=ViKtOr=-..
0
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.

MadshiCommented:
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;
begin
  c1:=SHGetFileInfo(pchar(exefile),0,sfi,SizeOf(sfi),SHGFI_EXETYPE);
  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;
end;

Regards, Madshi.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
viktornetCommented:
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...

;-)

..-=ViKtOr=-..
0
MadshiCommented:
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.
0
HencahAuthor Commented:
HI Madshi

I accept your answer, Big thanks

Cah
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.