472,965 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,965 software developers and data experts.

Getting all running Process names in windows

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
1 15831
hdanw
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

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
3
by: Ron | last post by:
I've written a screen saver which opens multiple copies on windows 98. I'm trying to check the process list to determine if it is already running. So far all the example win32 routines I've...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
0
by: Gary Thorne Jr. | last post by:
I am using the Debugging Tools for Windows v6.5.3.8 on Windows 2003 Server Web Edition SP1 and following the troubleshooting procedure from Microsoft "Debugging Contention Problems" at...
4
by: ImSoLost | last post by:
I'm running a really long process from ASP.NET and need some help... I am making a method call when the user presses a button from my webpage, which goes into a database and parses a file. This...
2
by: MSK | last post by:
Hi, Continued to my earlier post regaring "Breakpoints are not getting hit" , I have comeup with more input this time.. Kindly give me some idea. I am a newbie to .NET, recently I installed...
14
by: Alex K. | last post by:
Hi all I'd like to avoid starting the same c# application twice on the same computer. How do I check if it is already running? Thank you
5
by: =?Utf-8?B?dWxpbGxpbGxpYQ==?= | last post by:
I've had two issues plaguing me for 4 months now and I haven't gotten anywhere. I'm into making 2D games and these things are essential to games. These are my issues: 1. I need timing precise...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.