Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. RAM project

RAM project

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IndrekSnt
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • I IndrekSnt

      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

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      See if TerminateProcess() helps you.


      Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

      I 1 Reply Last reply
      0
      • D David Crow

        See if TerminateProcess() helps you.


        Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

        I Offline
        I Offline
        IndrekSnt
        wrote on last edited by
        #3

        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 D 2 Replies Last reply
        0
        • I IndrekSnt

          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 Offline
          I Offline
          IndrekSnt
          wrote on last edited by
          #4

          I'm really sorry about the mess above cause i got something... :)

          1 Reply Last reply
          0
          • I IndrekSnt

            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:

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            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?

            I 1 Reply Last reply
            0
            • D David Crow

              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?

              I Offline
              I Offline
              IndrekSnt
              wrote on last edited by
              #6

              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:

              D 1 Reply Last reply
              0
              • I IndrekSnt

                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:

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                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 to CListCtrl::InsertItem() in your code.


                Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

                I 1 Reply Last reply
                0
                • D David Crow

                  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 to CListCtrl::InsertItem() in your code.


                  Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

                  I Offline
                  I Offline
                  IndrekSnt
                  wrote on last edited by
                  #8

                  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:

                  D 1 Reply Last reply
                  0
                  • I IndrekSnt

                    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:

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    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?

                    I 1 Reply Last reply
                    0
                    • D David Crow

                      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?

                      I Offline
                      I Offline
                      IndrekSnt
                      wrote on last edited by
                      #10

                      :-D Thanks, it really helped me out, now i'm executing MSPAINT and NOTEPAD to terminate them... :)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups