By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,175 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,175 IT Pros & Developers. It's quick & easy.

Getting all running Process names in windows

P: 1
hi admin.. i followed your tip in "HOW TO LIST PROCESS ID IN WINDOWS" thread..and iam trying to compile this code in cygwin ,

$gcc -mno-cygwin process.c -o -L"psapi.lib" process.exe

psapi.h and psapi.lib are in this same folder as process.c file, i am getting lonf list of errors from psapi.lib

Process.c (from http://voice.mytechnopark.com/viewtopic.php?id=51)
Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <tchar.h>
  4. #include <psapi.h>
  5.  
  6. void main( )
  7. {
  8. DWORD ProcessesIDs[50], cbNeeded, cProcesses; 
  9. unsigned int i;
  10. //The default of <unknown> is given so that if GetModuleBaseName does not return 
  11. //the base name of the module then <unknown> will be printed instead of the base name.
  12.  
  13. TCHAR szProcessName[50] = TEXT("<unknown>");
  14.  
  15. //if Enumprocess returns zero (fails) then quit the program.
  16. if ( !EnumProcesses( ProcessesIDs, sizeof(ProcessesIDs), &cbNeeded ) )
  17. return; 
  18.  
  19. // Calculate how many process identifiers were returned.
  20. cProcesses = cbNeeded / sizeof(DWORD);
  21.  
  22. // This for loop will be enumerating each process.
  23. for ( i = 0; i < cProcesses; i++ )
  24. {
  25. // Get a handle to the process. The process to which the handle will be returned //will depend on the variable i.
  26.     HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ProcessesIDs[i] );
  27.  
  28.     // Get the process name.
  29.     if (NULL != hProcess )
  30.         {
  31.         GetModuleBaseName( hProcess, NULL, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) );
  32.         }
  33.  
  34.     // Print the process name and identifier.
  35.     _tprintf(TEXT("Processname = %s, PID = %u \n\n"), szProcessName, ProcessesIDs[i]);
  36.  
  37.     //Every handel is to be closed after its use is over.
  38.     CloseHandle( hProcess );
  39.     //End of for loop.
  40.     }
  41. }
  42.  
Output:
psapi.lib:90:73: warning: null character(s) ignored
psapi.lib:90: error: stray '\3' in program
psapi.lib:90:77: warning: null character(s) ignored
psapi.lib:90:83: warning: null character(s) ignored
psapi.lib:90: error: stray '\2' in program
psapi.lib:90:91: warning: null character(s) ignored
psapi.lib:90: error: stray '\3' in program
psapi.lib:90: error: stray '\1' in program
psapi.lib:90: error: stray '\6' in program
psapi.lib:90:97: warning: null character(s) ignored
psapi.lib:90: error: stray '\1' in program
psapi.lib:90:101: warning: null character(s) ignored
psapi.lib:90: error: stray '\1' in program
psapi.lib:90:111: warning: null character(s) ignored
psapi.lib:90:114: warning: null character(s) ignored
psapi.lib:91:1: warning: null character(s) ignored
psapi.lib:91: error: stray '\2' in program
psapi.lib:91:9: warning: null character(s) ignored
psapi.lib:91: error: stray '\2' in program
process.c:39: error: conflicting types for 'CloseHandle'
/usr/lib/gcc/i686-pc-mingw32/3.4.4/../../../../include/w32api/winbase.h:1169: error: previous declaration of 'CloseHandl
e' was here
process.c:39: warning: data definition has no type or storage class
process.c:41: error: parse error before '}' token
process.c:42:2: warning: no newline at end of file



P.S : I need this to work ..as it is a very important part of my final year project, please help in compiling this program

thanx in advance ..
Jan 16 '08 #1
Share this Question
Share on Google+
1 Reply


hdanw
P: 61
hi admin.. i followed your tip in "HOW TO LIST PROCESS ID IN WINDOWS" thread..and iam trying to compile this code in cygwin ,

$gcc -mno-cygwin process.c -o -L"psapi.lib" process.exe

psapi.h and psapi.lib are in this same folder as process.c file, i am getting lonf list of errors from psapi.lib

Process.c (from http://voice.mytechnopark.com/viewtopic.php?id=51)
Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <tchar.h>
  4. #include <psapi.h>
  5.  
  6. void main( )
  7. {
  8. DWORD ProcessesIDs[50], cbNeeded, cProcesses; 
  9. unsigned int i;
  10. //The default of <unknown> is given so that if GetModuleBaseName does not return 
  11. //the base name of the module then <unknown> will be printed instead of the base name.
  12.  
  13. TCHAR szProcessName[50] = TEXT("<unknown>");
  14.  
  15. //if Enumprocess returns zero (fails) then quit the program.
  16. if ( !EnumProcesses( ProcessesIDs, sizeof(ProcessesIDs), &cbNeeded ) )
  17. return; 
  18.  
  19. // Calculate how many process identifiers were returned.
  20. cProcesses = cbNeeded / sizeof(DWORD);
  21.  
  22. // This for loop will be enumerating each process.
  23. for ( i = 0; i < cProcesses; i++ )
  24. {
  25. // Get a handle to the process. The process to which the handle will be returned //will depend on the variable i.
  26. HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ProcessesIDs[i] );
  27.  
  28. // Get the process name.
  29. if (NULL != hProcess )
  30. {
  31. GetModuleBaseName( hProcess, NULL, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) );
  32. }
  33.  
  34. // Print the process name and identifier.
  35. _tprintf(TEXT("Processname = %s, PID = %u \n\n"), szProcessName, ProcessesIDs[i]);
  36.  
  37. //Every handel is to be closed after its use is over.
  38. CloseHandle( hProcess );
  39. //End of for loop.
  40. }
  41. }
  42.  
Output:
psapi.lib:90:73: warning: null character(s) ignored
psapi.lib:90: error: stray '\3' in program
psapi.lib:90:77: warning: null character(s) ignored
psapi.lib:90:83: warning: null character(s) ignored
psapi.lib:90: error: stray '\2' in program
psapi.lib:90:91: warning: null character(s) ignored
psapi.lib:90: error: stray '\3' in program
psapi.lib:90: error: stray '\1' in program
psapi.lib:90: error: stray '\6' in program
psapi.lib:90:97: warning: null character(s) ignored
psapi.lib:90: error: stray '\1' in program
psapi.lib:90:101: warning: null character(s) ignored
psapi.lib:90: error: stray '\1' in program
psapi.lib:90:111: warning: null character(s) ignored
psapi.lib:90:114: warning: null character(s) ignored
psapi.lib:91:1: warning: null character(s) ignored
psapi.lib:91: error: stray '\2' in program
psapi.lib:91:9: warning: null character(s) ignored
psapi.lib:91: error: stray '\2' in program
process.c:39: error: conflicting types for 'CloseHandle'
/usr/lib/gcc/i686-pc-mingw32/3.4.4/../../../../include/w32api/winbase.h:1169: error: previous declaration of 'CloseHandl
e' was here
process.c:39: warning: data definition has no type or storage class
process.c:41: error: parse error before '}' token
process.c:42:2: warning: no newline at end of file



P.S : I need this to work ..as it is a very important part of my final year project, please help in compiling this program

thanx in advance ..
note that the number is the line number of the error:

ie:
psapi.lib:90: error: stray '\3' in program

indicates that the error is on line 90 in the file psapi.lib, which is not shown here.

Dan-
Feb 5 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.