Ending a Process

This is a discussion on Ending a Process within the Windows Programming forums, part of the Platform Specific Boards category; does anyone know how to end a process??? i thought i had it and got these errors: C:\Program Files\Microsoft Visual ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    33

    Question Ending a Process

    does anyone know how to end a process??? i thought i had it and got these errors:

    C:\Program Files\Microsoft Visual Studio\MyProjects\ftp\ftp.cpp(49) : error C2664: 'GetExitCodeProcess' : cannot convert parameter 1 from 'int' to 'void *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

    C:\Program Files\Microsoft Visual Studio\MyProjects\ftp\ftp.cpp(51) : error C2664: 'TerminateProcess' : cannot convert parameter 1 from 'int' to 'void *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

    Here is my code now:


    Code:
    #include "stdafx.h"
    #include "iostream.h"
    #include "stdlib.h"
    #include "stdio.h"
    #include "fstream.h"
    #include "string.h"
    #include "windows.h"
    
    int main()
    {
    	char infos[30];
    	char ip[30];
    	char infoe[100];
    	char infop[100];
    	char info[100];
    	char pass[10];
    	char test[10];
    	char user[20];
    	int HANDLE;
    	int LPDWORD;
    	
    	
    	ifstream a_file("c:/test.txt");
    	a_file>>test;
    
    	strcpy(pass, test);
    		
        cout<<"Command to run:\n";  //Using if for explorer ftp://
    	cin.getline(infos, 30);
    
    	cout<<"Username + :\n";     //Getting accounts user name
    	cin>>user;
    
    	cout<<"@ + IP\n";           //Getting the IP address
    	cin>>ip;
    	
    	strcpy(infoe, infos);
    	strcat(infoe, user);        //Starts combining info
    
    	strcpy(infop, infoe);
    	strcat(infop, pass);
    
    	strcpy(info, infop);
    	strcat(info, ip);           //Finishes combining info
    
    	system(info);
    
    	HANDLE=GetCurrentProcessId();
    	GetExitCodeProcess(HANDLE, LPDWORD);
    
    	TerminateProcess(HANDLE, LPDWORD);
    
    	return 0;
    }
    This is just a program for fun and to mess around. I am hoping it will be able to read from a wordlist and try different passwords for my ftp until it gets the right pass. If you have any suggestions on if i should try a different route that would be great. Like i said this is just my own fun little project. Thanks

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    HANDLE is a type so don't use it as a variable name. I suspect that LPDWORD is, too ( ie DWORD* ).

    Errors like "can't convert from x to y" require that you cast to the correct type. Or you could recompile as a 'c' program and not 'c++'.

    With msvc if you highlight the error code and press F1, your help files will explain the nature of the error message and a possible solution. Alernatively you can check it on msdn, eg. C2664.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    33
    Ok i have read the MSDN and looked at some tuts but i am still having problems. I just copied and pasted what the MSDN stuff said and i dont get the same errors but i get these now:

    C:\Program Files\Microsoft Visual Studio\MyProjects\ftptest\ftptest.cpp(55) : error C2373: 'GetExitCodeProcess' : redefinition; different type modifiers
    c:\program files\microsoft visual studio\vc98\include\winbase.h(1680) : see declaration of 'GetExitCodeProcess'
    C:\Program Files\Microsoft Visual Studio\MyProjects\ftptest\ftptest.cpp(60) : error C2373: 'TerminateProcess' : redefinition; different type modifiers
    c:\program files\microsoft visual studio\vc98\include\winbase.h(1672) : see declaration of 'TerminateProcess'
    Error executing cl.exe.

    HERE IS MY CODE:

    Code:
    #include "stdafx.h"
    #include "iostream.h"
    #include "stdlib.h"
    #include "stdio.h"
    #include "fstream.h"
    #include "string.h"
    #include "Windows.h"
    #include "Winbase.h"
    
    int main()
    {
    	char infos[30];
    	char ip[30];
    	char infoe[100];
    	char infop[100];
    	char info[100];
    	char pass[10];
    	char test[10];
    	char user[20];
    	
    	
    	ifstream a_file("c:/test.txt");
    	a_file>>test;
    
    	strcpy(pass, test);
    		
        cout<<"Command to run:\n";  //Using if for explorer ftp://
    	cin.getline(infos, 30);
    
    	cout<<"Username + :\n";     //Getting accounts user name
    	cin>>user;
    
    	cout<<"@ + IP\n";           //Getting the IP address
    	cin>>ip;
    	
    	strcpy(infoe, infos);
    	strcat(infoe, user);        //Starts combining info
    
    	strcpy(infop, infoe);
    	strcat(infop, pass);
    
    	strcpy(info, infop);
    	strcat(info, ip);           //Finishes combining info
    
    	system(info);
    
    	DWORD GetProcessId(
        HANDLE hProcess
        );
    
    	
      BOOL GetExitCodeProcess(
      HANDLE hProcess,
      LPDWORD lpExitCode
      );
    
      BOOL TerminateProcess(
      HANDLE hProcess,
      UINT uExitCode
      );
    
    
    
    	return 0;
    }
    I really dont what to do, this is the first time i have tried to do anything like this so please help if you can...thanks.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You are redefining the functions and not calling them with actual values as you should.

    For example,
    Code:
    BOOL GetExitCodeProcess(
      HANDLE hProcess,
      LPDWORD lpExitCode
      )
    is a function declaration for GetExitCodeProcess which returns a BOOLean value and takes two parameters, the first of type HANDLE is represented by the variable namehProcess and the second of type LPDWORD represented by the variable name lpExitCode.

    Rather than simply copying and pasting stuff that you currently seem to be having difficulty understanding, perhaps you should spend a little time revising the fundamentals? For example, cprogramming has some tutorials here which may be of some use in this regard.

    Once you are more comfortable with the fundamentals (or, if you feel you already are) then you may wish to read up on processes and threads on msdn.

    That aside, you would declare variables of the types you need and then use these variables when calling the api function(s) of interest. For example, using GetExitCodeProcess:
    Code:
    HANDLE h;
    DWORD dw; /*the exit code will be stored in this variable */
    BOOL b; 
    /* once you have a handle for the process of interest stored in 'h', get the id */
    b=GetExitCodeProcess(h,&dw);
    /*you could then test the return value of the function ie the value of 'b' to check for success if you want */
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    system() generally returns the exit code so you don't need the API to get the return code. Further more, system(), as I understand it, will only return when the program is finished and is not compatible with the API.

    Try this (without the API functions):
    Code:
    int nExitCode = system("my command");
    printf("Program is finished. Exit Code was %d", nExitCode);
    You can then check the return code and decide what to do.

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    33
    Ok thanks guys and Ken Fitlike i did change it and when i couldnt figure it out i decided to copy and paste and i got some diff errors so i wasnt sure what was wrong...but i think i understand it better now...thanks for all the help

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    33
    Now can anyone tell my how i would check to see with the explorer ftp command worked?...i know if you have a wrong username or password it pops up with a login screen and i want to know if it poped up or it let me in? I hope u can understand. ummm for an example: ftp://admin:admin@10.10.10.1 and if the username and password dont match it pops up like a javascript login box or something like that. i just need to know how to check if it opens or not thanks

  8. #8
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Start a new thread.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  9. #9
    Registered User
    Join Date
    Apr 2003
    Posts
    33

    Talking

    can u explain a little more? I am reading about threads so if you could just go a little more in depth about it that would be great. thanks

  10. #10
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    No, I mean, post a new thread on the forum for your question, it's about something different.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  11. #11
    Registered User
    Join Date
    Apr 2003
    Posts
    33
    O ok lol

  12. #12
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    This function I wrote will work on ME systems as well. Pass to it the name of the application module in upper case (e.g. NOTEPAD.EXE). The function will return the number of terminated processes associated with the given module.
    Code:
    #include <windows.h>
    #include <tlhelp32.h>
    
    UINT win9x_stop_process(LPSTR lpModule) {
    
        HANDLE hProcess;
        PROCESSENTRY32 pe32;
        UINT ui = 0;
        HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    
        pe32.dwSize = sizeof(PROCESSENTRY32);
        Process32First(hSnapshot, &pe32);
    
        do {
    
            if ( lstrcmpi(strstr(pe32.szExeFile, lpModule), lpModule) == 0 ) {
    
                hProcess = OpenProcess(PROCESS_TERMINATE, TRUE, pe32.th32ProcessID);
                TerminateProcess(hProcess, 0);
                CloseHandle(hProcess);
                ui++;
    
            }
    
        } while ( Process32Next(hSnapshot, &pe32) );
    
        CloseHandle(hSnapshot);
        return ui;
    
    }
    Last edited by DarkStar; 10-25-2003 at 10:46 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 11:05 AM
  2. create a child process that creates a child process
    By cus in forum Linux Programming
    Replies: 9
    Last Post: 01-13-2009, 02:14 PM
  3. Replies: 3
    Last Post: 10-15-2008, 10:24 AM
  4. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 02:43 AM
  5. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 08:53 AM

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