Click to See Complete Forum and Search --> : [help] Visual c++ program for detecting a process running or not


rahuljin
June 5th, 2009, 01:02 PM
hello,

i want to detect the status of process running in the system using visual c++. i have visual studio 2008 in windows 7 rc.
i have the basic knowledge of c++ but i dont have any knowledge of .net platform.

i came to know that psapi.dll can be used for this purpose. but the problem is that i have never used such an advance programming (i have done the basic like looks, conditions, classes, file handling, etc. mostly in turbo c++ and some visual c++ also).

so can u provide some tutorial for psapi.dll and how to use it with visual c++ 2008. please help me.

btw thanks

rahul

ne0n82
June 5th, 2009, 10:42 PM
google tool help its a much easier api to use

davidpmp
June 6th, 2009, 08:59 AM
if you know the process main window title then you can search opened windows and get title to check and if you know the process path you can get all running processes and check process path.
if your environment is C++(NATIVE) you can search on MSDN for EnumProcess and if your environment is .NET is very easy to work with Process class and GetProcesses() method and check main window title and process path.

please give me more information about your Environemnt.I can make a sample for you if your Environemnt is .NET.

Best Regards,

rahuljin
June 6th, 2009, 10:25 AM
thanks guys. i have done most of work (i found some working code)

http://www.codeproject.com/KB/threads/Of_Services_and_Processes.aspx

when i run it, only limited number of processes are shown. if i run notepad, it does not show but nitropdf is there.

there is more problems too ---

can u tell me something about 'tchar'. i want to modify the code and want to show only for a specific process like notepad. PID is changing when the process is restarted. so cannot use this instruction

if(ProcessesIDs[i] == 2323)

so i have tried these but none of them is working ----

1) if(szProcessName == "notepad.exe")

2) if(szProcessName == TEST("notepad.exe"))

any help ?

ne0n82
June 6th, 2009, 10:28 AM
something like this should work

if ( wcscmp( szProcessName, TEXT("notepad.exe") ) == 0 ) {
//do stuff
}


Edit: you'll need to include <wchar.h> for that function

davidpmp
June 6th, 2009, 01:35 PM
#ifdef _UNICODE
#define TCHAR wchar_t
#else
#define TCHAR char
#endif

if you set the unicode character set then TCHAR is a wchar_t and is a unicode character and if you do not use unicode then TCHAR is equal to char. char is a byte (0 to 255) and can not store unicode characters on char.

thanks from ne0n82

TEXT("") & _T("") & T("") works like each other and encode string to your project Character set.

rahuljin
June 7th, 2009, 08:42 AM
thanks ne0n82, the code is working now.

i am facing some problems. when i create a win32 application(not console) in visual c++ and run it, the title bar is in chinese, but the system language is english.
i am using visual studio 2008.