RAM project
-
I want to finish a program that terminates proccesses that are selected in a big list. And my program must run always @ startup. How to terminate proccesses correctly selected in list? :wtf: My eyes - fountains of blood
See if
TerminateProcess()
helps you.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
See if
TerminateProcess()
helps you.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
I know that, ok, my code that doesn't work:
PROCESSENTRY32* info; HANDLE proc2; Process32First(proc2,info); for(int i=0;i<35;i++){ Process32Next(proc2,info); MessageBox(info->szExeFile,"OK"); if(strstr("NOTEPAD",info->szExeFile)){MessageBox("MATCH","OK");break;} } proc2=OpenProcess(/*PROCESS_ALL_ACCESS*/SYNCHRONIZE|PROCESS_TERMINATE,TRUE,1241980); m_name.Format("%d",info->th32ProcessID); SetDlgItemText(IDC_NAME,m_name.GetBuffer(0)); if(WaitForSingleObject(proc2,5000)!=WAIT_OBJECT_0){ result=TerminateProcess(proc2,0); MessageBox("Terminated","OK"); }else{ result=TRUE; cw=FindWindow(info->szExeFile,NULL); cw->PostMessage(WM_CLOSE); MessageBox("TRUE","VIGA"); } // if(!TerminateProcess(proc2,1)){ // } CloseHandle(proc2);
Well, it's only for testing... Such a mess for testing :rolleyes: -
I know that, ok, my code that doesn't work:
PROCESSENTRY32* info; HANDLE proc2; Process32First(proc2,info); for(int i=0;i<35;i++){ Process32Next(proc2,info); MessageBox(info->szExeFile,"OK"); if(strstr("NOTEPAD",info->szExeFile)){MessageBox("MATCH","OK");break;} } proc2=OpenProcess(/*PROCESS_ALL_ACCESS*/SYNCHRONIZE|PROCESS_TERMINATE,TRUE,1241980); m_name.Format("%d",info->th32ProcessID); SetDlgItemText(IDC_NAME,m_name.GetBuffer(0)); if(WaitForSingleObject(proc2,5000)!=WAIT_OBJECT_0){ result=TerminateProcess(proc2,0); MessageBox("Terminated","OK"); }else{ result=TRUE; cw=FindWindow(info->szExeFile,NULL); cw->PostMessage(WM_CLOSE); MessageBox("TRUE","VIGA"); } // if(!TerminateProcess(proc2,1)){ // } CloseHandle(proc2);
Well, it's only for testing... Such a mess for testing :rolleyes: -
I know that, ok, my code that doesn't work:
PROCESSENTRY32* info; HANDLE proc2; Process32First(proc2,info); for(int i=0;i<35;i++){ Process32Next(proc2,info); MessageBox(info->szExeFile,"OK"); if(strstr("NOTEPAD",info->szExeFile)){MessageBox("MATCH","OK");break;} } proc2=OpenProcess(/*PROCESS_ALL_ACCESS*/SYNCHRONIZE|PROCESS_TERMINATE,TRUE,1241980); m_name.Format("%d",info->th32ProcessID); SetDlgItemText(IDC_NAME,m_name.GetBuffer(0)); if(WaitForSingleObject(proc2,5000)!=WAIT_OBJECT_0){ result=TerminateProcess(proc2,0); MessageBox("Terminated","OK"); }else{ result=TRUE; cw=FindWindow(info->szExeFile,NULL); cw->PostMessage(WM_CLOSE); MessageBox("TRUE","VIGA"); } // if(!TerminateProcess(proc2,1)){ // } CloseHandle(proc2);
Well, it's only for testing... Such a mess for testing :rolleyes:PROCESSENTRY32 ProcessEntry;
ProcessEntry.dwSize = sizeof(PROCESSENTRY32); // important!
if (Process32First(hSnapshot, &ProcessEntry) == TRUE)
{
do
{
MessageBox(info->szExeFile, "OK");
if (strstr("NOTEPAD", info->szExeFile)
{
MessageBox("MATCH, "OK");
break;
}} while (Process32Next(hSnapshot, &ProcessEntry) == TRUE);
}
HANDLE hProcess = OpenProcess(/*PROCESS_ALL_ACCESS*/SYNCHRONIZE|PROCESS_TERMINATE, TRUE, ProcessEntry.th32ProcessID);
if (NULL != hProcess)
{
...
}
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
PROCESSENTRY32 ProcessEntry;
ProcessEntry.dwSize = sizeof(PROCESSENTRY32); // important!
if (Process32First(hSnapshot, &ProcessEntry) == TRUE)
{
do
{
MessageBox(info->szExeFile, "OK");
if (strstr("NOTEPAD", info->szExeFile)
{
MessageBox("MATCH, "OK");
break;
}} while (Process32Next(hSnapshot, &ProcessEntry) == TRUE);
}
HANDLE hProcess = OpenProcess(/*PROCESS_ALL_ACCESS*/SYNCHRONIZE|PROCESS_TERMINATE, TRUE, ProcessEntry.th32ProcessID);
if (NULL != hProcess)
{
...
}
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
HANDLE proc; PROCESSENTRY32* info; POSITION p; int sel=0; BOOL result; char *name2; int length=0; proc=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); info=new PROCESSENTRY32; info->dwSize=sizeof(PROCESSENTRY32); int id=0; Process32First(proc,info); p=m_list1.GetFirstSelectedItemPosition(); sel=m_list1.GetNextSelectedItem(p); do{ Process32Next(proc,info); }while(!strstr(info->szExeFile,"NOTEPAD")); proc=OpenProcess(/*PROCESS_ALL_ACCESS*/SYNCHRONIZE|PROCESS_TERMINATE,TRUE,info->th32ProcessID); m_name.Format("%s",info->szExeFile); SetDlgItemText(IDC_NAME,m_name.GetBuffer(0)); if(WaitForSingleObject(proc,5000)!=WAIT_OBJECT_0){ result=TerminateProcess(proc,0); MessageBox("Terminated","OK"); }else{ result=TRUE; cw=FindWindow(info->szExeFile,NULL); cw->PostMessage(WM_CLOSE); MessageBox("TRUE","VIGA"); } CloseHandle(proc); delete info;
Well, this should work, but how to use m_mylist.GetItemText(int nItem,intnSubItem,LPTSTR lpszText,innLen) with my code? :confused: -
HANDLE proc; PROCESSENTRY32* info; POSITION p; int sel=0; BOOL result; char *name2; int length=0; proc=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); info=new PROCESSENTRY32; info->dwSize=sizeof(PROCESSENTRY32); int id=0; Process32First(proc,info); p=m_list1.GetFirstSelectedItemPosition(); sel=m_list1.GetNextSelectedItem(p); do{ Process32Next(proc,info); }while(!strstr(info->szExeFile,"NOTEPAD")); proc=OpenProcess(/*PROCESS_ALL_ACCESS*/SYNCHRONIZE|PROCESS_TERMINATE,TRUE,info->th32ProcessID); m_name.Format("%s",info->szExeFile); SetDlgItemText(IDC_NAME,m_name.GetBuffer(0)); if(WaitForSingleObject(proc,5000)!=WAIT_OBJECT_0){ result=TerminateProcess(proc,0); MessageBox("Terminated","OK"); }else{ result=TRUE; cw=FindWindow(info->szExeFile,NULL); cw->PostMessage(WM_CLOSE); MessageBox("TRUE","VIGA"); } CloseHandle(proc); delete info;
Well, this should work, but how to use m_mylist.GetItemText(int nItem,intnSubItem,LPTSTR lpszText,innLen) with my code? :confused:IndrekSnt wrote: }while(!strstr(info->szExeFile,"NOTEPAD")); This will loop forever if Notepad is not running! IndrekSnt wrote: ...how to use m_mylist.GetItemText(int nItem,intnSubItem,LPTSTR lpszText,innLen)... In order to use
CListCtrl::GetItemText()
, you must first have added items to the list control. I do not see any calls toCListCtrl::InsertItem()
in your code.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
IndrekSnt wrote: }while(!strstr(info->szExeFile,"NOTEPAD")); This will loop forever if Notepad is not running! IndrekSnt wrote: ...how to use m_mylist.GetItemText(int nItem,intnSubItem,LPTSTR lpszText,innLen)... In order to use
CListCtrl::GetItemText()
, you must first have added items to the list control. I do not see any calls toCListCtrl::InsertItem()
in your code.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
I'm not copying all my code but the InsertItem() functions are here:
proc=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); info=new PROCESSENTRY32; info->dwSize=sizeof(PROCESSENTRY32); int id=0; Process32First(proc,info); m_list1.InsertItem(0,(LPCTSTR)info->szExeFile); while(Process32Next(proc,info)!=FALSE){ id++; m_list1.InsertItem(id,(LPCTSTR)info->szExeFile); } CloseHandle(proc);
This here was too only a segment of the code... :omg: -
I'm not copying all my code but the InsertItem() functions are here:
proc=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); info=new PROCESSENTRY32; info->dwSize=sizeof(PROCESSENTRY32); int id=0; Process32First(proc,info); m_list1.InsertItem(0,(LPCTSTR)info->szExeFile); while(Process32Next(proc,info)!=FALSE){ id++; m_list1.InsertItem(id,(LPCTSTR)info->szExeFile); } CloseHandle(proc);
This here was too only a segment of the code... :omg:Assuming your list control had another column:
int x = m_list1.InsertItem(0,(LPCTSTR)info->szExeFile);
sprintf(szProcId, "%lu", info->th32ProcessID);
m_list1.SetItemText(x, 1, szProcId);Otherwise, you'll need to use:
int x = m_list1.InsertItem(0,(LPCTSTR)info->szExeFile);
LPDWORD lpProcId = new DWORD;
*lpProcId = info->th32ProcessID;
m_list1.SetItemData(x, lpProcId);
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
Assuming your list control had another column:
int x = m_list1.InsertItem(0,(LPCTSTR)info->szExeFile);
sprintf(szProcId, "%lu", info->th32ProcessID);
m_list1.SetItemText(x, 1, szProcId);Otherwise, you'll need to use:
int x = m_list1.InsertItem(0,(LPCTSTR)info->szExeFile);
LPDWORD lpProcId = new DWORD;
*lpProcId = info->th32ProcessID;
m_list1.SetItemData(x, lpProcId);
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?