Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the PID on WINNT & WIN2000

Status
Not open for further replies.

labnotes

Technical User
Sep 1, 2003
33
CA
Using PERL I can run pulist.exe and step through each line using with Win32::process loaded. I am using Bloodshed dev-C++ ver.4.9.8.0. Can I do the same with a
C++ function?
 
'EnumProcesses' could be used, but isn't too helpful as cannot link process names to there appropriate PID's. You can use a ToolHelp function, like in the program below (just lists all process names and there PID's):
Code:
#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  HANDLE hconsoleInput, hconsoleOutput;
  char string[100];
  DWORD written;
  HANDLE hSnapShot;
  PROCESSENTRY32 ProcEntry;
  BOOL hRes;

  AllocConsole();
  hconsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  hconsoleInput  = GetStdHandle(STD_INPUT_HANDLE);
	
  hSnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
  ProcEntry.dwSize = sizeof(ProcEntry);
  Process32First(hSnapShot, &ProcEntry);
  while(1)
  {
    hRes = Process32Next (hSnapShot, &ProcEntry);
    if (hRes == FALSE)
	break;
    sprintf(string,&quot;  %s %x\n&quot;,ProcEntry.szExeFile, ProcEntry.th32ProcessID);
    WriteConsole(hconsoleOutput,string,strlen(string),&written,0);
  }
  ReadConsole(hconsoleInput,string,1,&written,0);
  return (0);
}
Hope that is useful. :)
 
>> The above code doesn't work on a Win NT machine

NT What version? Your first post does not even indicate NT as a constraint let alone what version. If you have specific constraints for your solution you surely need to provide them in your post right? Otherwise how is anyone out here supposed to know about it, magic?

>> but I run into a road block with __leave and I don't
>> understand the information I found on

Sorry but I just don’t understand that. It seems that whatever you replaced with the [red]……[/red] might be needed to complete that statement.


-pete
 
You are correct sorry windows NT 4 Sp6. The &quot;__leave&quot; is part of the code on the
MSDN web site.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top