process killer on a loop

This is a discussion on process killer on a loop within the Windows Programming forums, part of the Platform Specific Boards category; i cant seem to be able to keep looping with goto , it stops after 1 go through all the ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    310

    process killer on a loop

    i cant seem to be able to keep looping with goto , it stops after 1
    go through all the process's
    can anyone help
    Code:
    #include <iostream>
    #include <windows.h>
    #include <string>
    #include <shellapi.h>
    #include <Tlhelp32.h>
    #include <iostream>
    using namespace std;
    
    
    
    //DWORD WINAPI mythread(LPVOID)
    int main()
    {
    start:
    
    HANDLE openprocess;
    HANDLE hProcessSnap;
    hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPALL, 0 );
    PROCESSENTRY32 pe32;
    pe32.dwSize = sizeof(PROCESSENTRY32);
    
    openprocess = OpenProcess(PROCESS_TERMINATE,TRUE,pe32.th32ProcessID);
    
    Process32First(hProcessSnap, &pe32);
    ///////////////////////Process32Next 1/////////////////////////////////////////////////
    Process32Next(hProcessSnap, &pe32); //System
    Process32Next(hProcessSnap, &pe32); 
    procnext:
    Process32Next(hProcessSnap, &pe32);
    if( //begin of if
      (strcmp(pe32.szExeFile, "System") == 0) ||
      (strcmp(pe32.szExeFile, "WINLOGON.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "winlogon.exe") == 0) ||
      (strcmp(pe32.szExeFile, "svchost.exe") == 0) ||
      (strcmp(pe32.szExeFile, "SVCHOST.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "csrss.exe") == 0) ||
      (strcmp(pe32.szExeFile, "CSRSS.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "SMSS.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "smss.exe") == 0) ||
      (strcmp(pe32.szExeFile, "SYSTEM.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "System.exe") == 0) ||
      (strcmp(pe32.szExeFile, "SERVICES.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "services.exe") == 0) ||
      (strcmp(pe32.szExeFile, "LSASS.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "lsass.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wmiprvse.exe") == 0) ||
      (strcmp(pe32.szExeFile, "WMIPRVSE.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "EXPLORER.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "Explorer.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "explorer.exe") == 0) ||
      (strcmp(pe32.szExeFile, "IEXPLORE.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "iexplore.exe") == 0) ||
      (strcmp(pe32.szExeFile, "rundll32.exe") == 0) ||
      (strcmp(pe32.szExeFile, "RUNDLL32.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "logonui.exe") == 0) ||
      (strcmp(pe32.szExeFile, "LOGONUI.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "userinit.exe") == 0) ||
      (strcmp(pe32.szExeFile, "USERINIT.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "mstask.exe") == 0) ||
      (strcmp(pe32.szExeFile, "MSTASK.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "ASPNet_State.exe") == 0) ||
      (strcmp(pe32.szExeFile, "cidaemon.exe") == 0) ||
      (strcmp(pe32.szExeFile, "Untitled1.exe") == 0) ||
      (strcmp(pe32.szExeFile, "ctfmon.exe") == 0) ||
      (strcmp(pe32.szExeFile, "dllhost.exe") == 0) ||
      (strcmp(pe32.szExeFile, "dumprep.exe") == 0) ||
      (strcmp(pe32.szExeFile, "grpconv.exe") == 0) ||
      (strcmp(pe32.szExeFile, "grpconv.exe") == 0) ||
      (strcmp(pe32.szExeFile, "internat.exe") == 0) ||
      (strcmp(pe32.szExeFile, "loadwc.exe") == 0) ||
      (strcmp(pe32.szExeFile, "lsass.exe") == 0) ||
      (strcmp(pe32.szExeFile, "mscorsvw.exe") == 0) ||
      (strcmp(pe32.szExeFile, "msiexec.exe") == 0) ||
      (strcmp(pe32.szExeFile, "mstinit.exe") == 0) ||
      (strcmp(pe32.szExeFile, "netdde.exe") == 0) ||
      (strcmp(pe32.szExeFile, "ntvdm.exe") == 0) ||
      (strcmp(pe32.szExeFile, "rasautou.exe") == 0) ||
      (strcmp(pe32.szExeFile, "regsvc.exe") == 0) ||
      (strcmp(pe32.szExeFile, "rpcss.exe") == 0) ||
      (strcmp(pe32.szExeFile, "RTHDCPL.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "runonce.exe") == 0) ||
      (strcmp(pe32.szExeFile, "scanregw.exe") == 0) ||
      (strcmp(pe32.szExeFile, "spool32.exe") == 0) ||
      (strcmp(pe32.szExeFile, "spupdsvc.exe") == 0) ||
      (strcmp(pe32.szExeFile, "systray.exe") == 0) ||
      (strcmp(pe32.szExeFile, "taskman.exe") == 0) ||
      (strcmp(pe32.szExeFile, "tlntsvr.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wgatray.exe") == 0) ||
      (strcmp(pe32.szExeFile, "winoa386.mod") == 0) ||
      (strcmp(pe32.szExeFile, "WMIADAP.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "rpcss.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wmipvse.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wscntfy.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wuauboot.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wucrtupd.exe") == 0) ||
      (strcmp(pe32.szExeFile, "actmovie.exe") == 0) ||
      (strcmp(pe32.szExeFile, "ASPNET_WP.exe") == 0) ||
      (strcmp(pe32.szExeFile, "cisvc.exe") == 0) ||
      (strcmp(pe32.szExeFile, "comres.dll") == 0) ||
      (strcmp(pe32.szExeFile, "CPQEAKSYSTEMTRAY.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "ddhelp.exe") == 0) ||
      (strcmp(pe32.szExeFile, "dos4gw.exe") == 0) ||
      (strcmp(pe32.szExeFile, "hidserv.exe") == 0) ||
      (strcmp(pe32.szExeFile, "inetinfo.exe") == 0) ||
      (strcmp(pe32.szExeFile, "kernel32.dll") == 0) ||
      (strcmp(pe32.szExeFile, "locator.exe") == 0) ||
      (strcmp(pe32.szExeFile, "mad.exe") == 0) ||
      (strcmp(pe32.szExeFile, "mmc.exe") == 0) ||
      (strcmp(pe32.szExeFile, "mqrt.dll") == 0) ||
      (strcmp(pe32.szExeFile, "msdtc.exe") == 0) ||
      (strcmp(pe32.szExeFile, "msoobe.exe") == 0) ||
      (strcmp(pe32.szExeFile, "tftp.exe") == 0) ||
      (strcmp(pe32.szExeFile, "TFTP.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "FTP.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "ftp.exe") == 0) ||
      (strcmp(pe32.szExeFile, "narrator.exe") == 0) ||
      (strcmp(pe32.szExeFile, "netsvcs") == 0) ||
      (strcmp(pe32.szExeFile, "pchschd.exe") == 0) ||
      (strcmp(pe32.szExeFile, "rdpclip.exe") == 0) ||
      (strcmp(pe32.szExeFile, "regsvr32.exe") == 0) ||
      (strcmp(pe32.szExeFile, "rstrui.exe") == 0) ||
      (strcmp(pe32.szExeFile, "rundll.exe") == 0) ||
      (strcmp(pe32.szExeFile, "sapisvr.exe") == 0) ||
      (strcmp(pe32.szExeFile, "scardsvr.exe") == 0) ||
      (strcmp(pe32.szExeFile, "smss.exe") == 0) ||
      (strcmp(pe32.szExeFile, "spoolsv.exe") == 0) ||
      (strcmp(pe32.szExeFile, "srvany.exe") == 0) ||
      (strcmp(pe32.szExeFile, "system") == 0) ||
      (strcmp(pe32.szExeFile, "tabbtnu.exe") == 0) ||
      (strcmp(pe32.szExeFile, "WISPTIS.EXE") == 0) ||
      (strcmp(pe32.szExeFile, "wmiexe.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wowexec.exe") == 0) ||
      (strcmp(pe32.szExeFile, "WtSrv.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wuauclt.exe") == 0) ||
      (strcmp(pe32.szExeFile, "agentsvr.exe") == 0) ||
      (strcmp(pe32.szExeFile, "ccmexec.exe") == 0) ||
      (strcmp(pe32.szExeFile, "clisvcl.exe") == 0) ||
      (strcmp(pe32.szExeFile, "Control.exe") == 0) ||
      (strcmp(pe32.szExeFile, "csrss.exe") == 0) ||
      (strcmp(pe32.szExeFile, "dfssvc.exe") == 0) ||
      (strcmp(pe32.szExeFile, "dotnetfx.exe") == 0) ||
      (strcmp(pe32.szExeFile, "fast.exe") == 0) ||
      (strcmp(pe32.szExeFile, "InstmsiW.exe") == 0) ||
      (strcmp(pe32.szExeFile, "launch32.exe") == 0) ||
      (strcmp(pe32.szExeFile, "mapisp32.exe") == 0) ||
      (strcmp(pe32.szExeFile, "mmtask.tsk") == 0) ||
      (strcmp(pe32.szExeFile, "msgsrv32.exe") == 0) ||
      (strcmp(pe32.szExeFile, "mstask.exe") == 0) ||
      (strcmp(pe32.szExeFile, "ndisuio.sys") == 0) ||
      (strcmp(pe32.szExeFile, "ntoskrnl.exe") == 0) ||
      (strcmp(pe32.szExeFile, "pstores.exe") == 0) ||
      (strcmp(pe32.szExeFile, "RDSHOST.exe") == 0) ||
      (strcmp(pe32.szExeFile, "rnaapp.exe") == 0) ||
      (strcmp(pe32.szExeFile, "rsvp.exe") == 0) ||
      (strcmp(pe32.szExeFile, "rundll32.exe") == 0) ||
      (strcmp(pe32.szExeFile, "snmp.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wuaudt.exe") == 0) ||
      (strcmp(pe32.szExeFile, "StillImageMonitor") == 0) ||
      (strcmp(pe32.szExeFile, "System Idle Process") == 0) ||
      (strcmp(pe32.szExeFile, "tapisrv.exe") == 0) ||
      (strcmp(pe32.szExeFile, "tcpsvcs.exe") == 0) ||
      (strcmp(pe32.szExeFile, "uwdf.exe") == 0) ||
      (strcmp(pe32.szExeFile, "winmgmt.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wlballoon") == 0) ||
      (strcmp(pe32.szExeFile, "wmiprvse.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wpabaln.exe") == 0) ||
      (strcmp(pe32.szExeFile, "wuaclt.exe") == 0) ||
      (strcmp(pe32.szExeFile, "spoolss.exe") == 0) ||
      (strcmp(pe32.szExeFile, "mirc.exe") == 0) ||
      (strcmp(pe32.szExeFile, "rBot.exe") == 0) ||
      (strcmp(pe32.szExeFile, "windowsp.exe") == 0) || 
      (strcmp(pe32.szExeFile, "try.exe") == 0) ||
      (strcmp(pe32.szExeFile, "CMD.exe") == 0) ||
      (strcmp(pe32.szExeFile, "cmd.exe") == 0) ||
      (strcmp(pe32.szExeFile, "DevCpp.exe") == 0)
      ) 
      
      
      
      
      {}
      
      else
      
      {openprocess = OpenProcess(PROCESS_TERMINATE,TRUE,pe32.th32ProcessID);TerminateProcess(openprocess,0);}
      
      
      if ( GetLastError() != ERROR_NO_MORE_FILES ){goto procnext;}
      
      else
    
      {goto start;}
      
      return 0;
      
      }

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Looks like you are/where a VB programmer.

    'goto' is not used in C/C++ as it is considered dangerous and bad practice.

    I suggest your code needs to be broken into smaller functions, (ie check if process found, want to terminate current process, ect).

    I would use a while loop (or could be recursive).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    goto is used, never using goto is as bad a habit as using it often, however, this is a terrible use of it.
    You might try something like this, note that if you don't add a condition or a break it will loop forever.
    Code:
    /* ... */
    for(;;)
    {
        /* start stuff */
        do
        {
            /* whatever ... */
            Process32Next(hProcessSnap, &pe32);
        } while (GetLastError() != ERROR_NO_MORE_FILES);
    }
    /* ... */

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    'goto' is not used in C/C++ as it is considered dangerous and bad practice.
    goto isn't used in C?? Wow, I learn something new every day!

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Oh, and your code should loop forever. The only reason I can think of that your program is stopping is that you are ending your own program's process with the TerminateProcess() call.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Excuse me for simplifing for a poster who I thought was new to C/C++

    I should have said goto is not used in C/C++ in the same way it is used in VB.



    I have never HAD to use goto (in C/C++) in the last ten years.

    Have you? If so post it.
    Last edited by novacain; 01-10-2006 at 02:11 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Have you? If so post it.
    I've used goto several times. I don't feel like searching through old projects, so I'll just leave you with this:

    http://cvs.opensolaris.org/source/xr...mon/os/sched.c

    I count 9 uses of goto in just the process scheduler. Just because your computer science professor told you goto was evil doesn't make it true.

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    OH, by the way. There was a computer science professor at Stanford who optimized one of his programs loops by 12%. The trick to this optimization was that he optimized it with goto.

    His name was Donald Knuth. For those of you who have heard that name, it's obvious that the game has changed, isn't it?
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    There's a big difference between using goto "just because you can", or "because I'm too dumb to use proper coding techniques" and having to use goto because that's the only optimization step left open before resorting to asm.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. create a child process that creates a child process
    By cus in forum Linux Programming
    Replies: 9
    Last Post: 01-13-2009, 01:14 PM
  2. Replies: 8
    Last Post: 12-01-2008, 09:09 AM
  3. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  4. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-30-2006, 11:59 PM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21