Copying self...?

This is a discussion on Copying self...? within the Windows Programming forums, part of the Platform Specific Boards category; I'm writing a program for win32. I need to know how to make it copy itself to LOCATION_X. here's my ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220

    Question Copying self...?

    I'm writing a program for win32. I need to know how to make it copy itself to LOCATION_X.
    here's my code.

    Code:
    #include <windowsx.h>
    #include <commctrl.h>
    #include <string.h>
    #include <conio.h>
    #include <stdio.h>
    #define LOCATION_X "c:\\test.exe"
    
    int APIENTRY WinMain(HINSTANCE hinst, HISTANCE hinstPrev, LPSTR lpCmdLine, int nCmdShow)
    {
     CopyFile( ????NEED HELP HERE????, LOCATION_X, FALSE);
     return 0;
    }
    any ideas?
    Last edited by Brian; 01-26-2002 at 08:49 PM.

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Oh, and this is in LCC-win32. (not DJGPP) all I need to know is how to get the name of the program that is running (itself)
    Last edited by Brian; 01-26-2002 at 08:51 PM.

  3. #3
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Something like -

    TCHAR buff[256];
    GetModuleFileName(NULL,buff,256);

    buff will contain the full path.

    ...hmm - self-replicating file == virus ??

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You get the full path & filename of the current process with the 'lpCmdLine' param passed to WinMain ( I think). If you don't then you certainly will with the GetCommandLine fn. In either case you will have to parse it to get the info you require.

    Hope that helps some.

    Edited: Actually go with Sorensen's vastly superior 'GetModuleFileName'
    suggestion.
    Last edited by Ken Fitlike; 01-26-2002 at 09:03 PM.

  5. #5
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Originally posted by Sorensen
    Something like -

    TCHAR buff[256];
    GetModuleFileName(NULL,buff,256);

    buff will contain the full path.

    That was it thanks.

    ...hmm - self-replicating file == virus ??
    No.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying Files
    By ch4 in forum C Programming
    Replies: 8
    Last Post: 02-14-2009, 04:15 PM
  2. Deep and Shallow Copying
    By peckitt99 in forum C++ Programming
    Replies: 4
    Last Post: 08-18-2007, 10:37 PM
  3. Copying a whole directory and its content
    By Enira in forum C Programming
    Replies: 4
    Last Post: 03-12-2006, 02:13 PM
  4. Shallow/Deep copying, pointers
    By littleweseth in forum C++ Programming
    Replies: 3
    Last Post: 11-26-2003, 06:36 PM
  5. Copying a file
    By rkjd2 in forum C++ Programming
    Replies: 5
    Last Post: 09-09-2001, 11:24 AM

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