Click here to Skip to main content
15,920,801 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Any File Encryption Pin
Genius Am Not15-May-07 1:17
Genius Am Not15-May-07 1:17 
GeneralRe: Any File Encryption Pin
Arman S.15-May-07 2:20
Arman S.15-May-07 2:20 
GeneralRe: Any File Encryption Pin
Genius Am Not20-May-07 22:52
Genius Am Not20-May-07 22:52 
QuestionTrack other processes in the computer Pin
kamalesh8214-May-07 23:58
kamalesh8214-May-07 23:58 
AnswerRe: Track other processes in the computer [modified] Pin
Arman S.15-May-07 0:10
Arman S.15-May-07 0:10 
AnswerRe: Track other processes in the computer Pin
AkiraOne15-May-07 0:15
AkiraOne15-May-07 0:15 
AnswerRe: Track other processes in the computer Pin
Hamid_RT15-May-07 0:58
Hamid_RT15-May-07 0:58 
AnswerRe: Track other processes in the computer Pin
kasturi_haribabu15-May-07 1:08
kasturi_haribabu15-May-07 1:08 
Pls Find answer to your code....
I dont know how i can attach a file to code project message. there fore please copy from the message...


/* Header File for the Class /*

#include "stdafx.h"
#include "psapi.h"
#pragma pack(16)

#define FOUND_WJRU 0
#define WJRU_NOTFOUND 1

class CProcessMonitor
{
private:
DWORD mAvailableProcesses[1024], cbNeeded, cProcesses;
public:
UINT getTotalAvailableProcesses();
UINT getProcessTimes();
BOOL FindProcessandMemoryDetails(DWORD processID,CString Processname,PROCESS_MEMORY_COUNTERS& psmemCounters);
BOOL IsProcessMatchingNameAndID( DWORD processID, UINT index );
HANDLE GetProcessHandle(DWORD processID, CString Processname);
HANDLE GetHandleToProcess(CString Processname);
void GetJRUStatus(int&nStatus, PROCESS_MEMORY_COUNTERS& psMemInfo);

};


#pragma pack()




/// CPLUSS PLUS FILE....

#include "stdafx.h"
#include "psapi.h"
#include "EnumProcess.h"

BOOL CProcessMonitor::IsProcessMatchingNameAndID( DWORD processID, UINT index )
{
char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH] = "Wjru.exe";

PROCESS_MEMORY_COUNTERS psmemCounters;

// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );

// Get the process name.
if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;

if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );

if(strcmp(szProcessName,szTargetProcessName) ==0)
{

GetProcessMemoryInfo(hProcess,&psmemCounters,sizeof(PROCESS_MEMORY_COUNTERS));


return TRUE;
}
else
{
return FALSE;
}
}
}
return FALSE;
}

BOOL CProcessMonitor::FindProcessandMemoryDetails(DWORD processID, CString Processname,PROCESS_MEMORY_COUNTERS& psmemCounters)
{

char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH];

strcpy(szTargetProcessName,Processname.GetBuffer(50));
Processname.ReleaseBuffer();


// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );

// Get the process name.
if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;

if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );

if(strcmp(szProcessName,szTargetProcessName) ==0)
{

GetProcessMemoryInfo(hProcess,&psmemCounters,sizeof(PROCESS_MEMORY_COUNTERS));
return TRUE;
}
else
{
return FALSE;
}
}
}
return FALSE;
}


void CProcessMonitor::GetJRUStatus(int& nStatus, PROCESS_MEMORY_COUNTERS& psMemInfo)
{

ULONG lCpuusage = 0;
UINT index;
//Find Total Number of Processes;
if (!EnumProcesses( mAvailableProcesses, sizeof(mAvailableProcesses), &cbNeeded ) )
return;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
if(cProcesses > 1000)
{
AfxMessageBox("There are Too Many applications Running on PC.");
}

PROCESS_MEMORY_COUNTERS psTempMemInfo;

for ( index = 0; index < cProcesses; index++ )
{
if(FindProcessandMemoryDetails(mAvailableProcesses[index],"Wjru.exe",psTempMemInfo)== TRUE)
{
nStatus = FOUND_WJRU;
psMemInfo = psTempMemInfo;
return;
}
}

nStatus = WJRU_NOTFOUND;

}


HANDLE CProcessMonitor::GetProcessHandle(DWORD processID, CString Processname)
{

char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH];

strcpy(szTargetProcessName,Processname.GetBuffer(50));
Processname.ReleaseBuffer();
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );

// Get the process name.
if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;

if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );

if(strcmp(szProcessName,szTargetProcessName) ==0)
{
return hProcess;
}
else
{
return NULL;
}
}
}


return NULL;
}




HANDLE CProcessMonitor::GetHandleToProcess(CString ProcessName)
{
HANDLE hProcess;
hProcess = NULL;

char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH];

strcpy(szTargetProcessName,ProcessName.GetBuffer(50));
ProcessName.ReleaseBuffer();

ULONG lCpuusage = 0;
UINT index;

//Find Total Number of Processes;
if (!EnumProcesses( mAvailableProcesses, sizeof(mAvailableProcesses), &cbNeeded ) )
return hProcess;

// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);

if(cProcesses > 1000)
{
AfxMessageBox("There are Too Many applications Running on PC.");
}

for ( index = 0; index < cProcesses; index++ )
{
hProcess= GetProcessHandle(mAvailableProcesses[index],szTargetProcessName);
if(hProcess != NULL)
{
return hProcess;
}
}
return hProcess;
}








Haribabu....
GeneralRe: Track other processes in the computer Pin
Hamid_RT15-May-07 1:18
Hamid_RT15-May-07 1:18 
GeneralRe: Track other processes in the computer Pin
kamalesh8215-May-07 1:20
kamalesh8215-May-07 1:20 
Questionchanging row colour Pin
neha.agarwal2714-May-07 23:53
neha.agarwal2714-May-07 23:53 
AnswerRe: changing row colour Pin
Hamid_RT15-May-07 0:45
Hamid_RT15-May-07 0:45 
AnswerRe: changing row colour Pin
Nelek15-May-07 0:48
protectorNelek15-May-07 0:48 
QuestionProblem with constructor overloading... Pin
sandeepkavade14-May-07 23:46
sandeepkavade14-May-07 23:46 
AnswerRe: Problem with constructor overloading... Pin
Cedric Moonen14-May-07 23:54
Cedric Moonen14-May-07 23:54 
GeneralRe: Problem with constructor overloading... Pin
sandeepkavade14-May-07 23:57
sandeepkavade14-May-07 23:57 
AnswerRe: Problem with constructor overloading... Pin
Arman S.15-May-07 0:00
Arman S.15-May-07 0:00 
QuestionRe: Problem with constructor overloading... Pin
David Crow15-May-07 3:25
David Crow15-May-07 3:25 
QuestionNeed help. I am trying to implement UDP for transferring file Pin
yaminisridaran14-May-07 23:26
yaminisridaran14-May-07 23:26 
AnswerRe: Need help. I am trying to implement UDP for transferring file Pin
Hamid_RT15-May-07 0:53
Hamid_RT15-May-07 0:53 
GeneralRe: Need help. I am trying to implement UDP for transferring file Pin
yaminisridaran15-May-07 1:23
yaminisridaran15-May-07 1:23 
GeneralRe: Need help. I am trying to implement UDP for transferring file Pin
Hamid_RT15-May-07 1:51
Hamid_RT15-May-07 1:51 
GeneralRe: Need help. I am trying to implement UDP for transferring file Pin
#realJSOP15-May-07 1:54
professional#realJSOP15-May-07 1:54 
GeneralRe: Need help. I am trying to implement UDP for transferring file Pin
Stephen Hewitt15-May-07 15:16
Stephen Hewitt15-May-07 15:16 
GeneralRe: Need help. I am trying to implement UDP for transferring file Pin
#realJSOP15-May-07 23:19
professional#realJSOP15-May-07 23:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.