Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List Processes
#1
Just a small c++ script I found ages ago but editted slightly by me, when run this program will show all process's that are running as well as their ids. Can be usefull for use with other scripts or to help protect your system from viruses


Code:
/*When run this program will show all processes that are running as well as their ids*/
#include <stdio.h>
#include <windows.h>
#include <tlhelp32.h>

int main(void)
{
    int info;
    HANDLE Snap;
    PROCESSENTRY32 proc32;
    
    Snap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);/*take a snap of all processes*/
  if(Snap==INVALID_HANDLE_VALUE)
  {
    printf("Error creating snapshot of current processes");
    return EXIT_FAILURE;
  }
  proc32.dwSize=sizeof(PROCESSENTRY32); /*set size of structure*/  
  
  system("cls");
  printf("Process Viewer\n");
  printf("PID:\t\tPROCESS NAME:\n");
  while((Process32Next(Snap,&proc32))==TRUE)/*while we haven't reached the final process*/
  {
      printf("\n%d\t\t%s",proc32.th32ProcessID,proc32.szExeFile);/*print pid and processname*/
  }
  printf("\n");
  CloseHandle(Snap);/*cleaning up*/  
  system("PAUSE");            
  return EXIT_SUCCESS;
}
Reply
#2
Thanks that's useful!
Just a little addition is that when used as it is in Visual Studio I can't see the full process name, just the first character.
The solution to that is to have the Conversion Code %ls instead of %s in printf, because proc32.szExeFile is of type WCHAR

printf("\n%d\t\t%ls",proc32.th32ProcessID,proc32.szExeFile);/*print pid and processname*/
Reply
#3
ah ok, i just use dev-cpp so i didn't test with visual studio but thanks for that Smile
Reply
#4
Usefull
[Image: 2d75599e9a.png]:superman:
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)