ok, so first of all I'm a complete noob in programming and I've been trying to teach myself on and off for a little now, so don't be too hard on me ;)
I was trying to write a program that will copy itself into another folder (seems like an easy enough program), but i cant seem to figure it out.
using namespace std;
int main ()
if (CopyFile (getlocation, "C:\\end destination"))
cout << "File could not be copied successfully";
cout << "File copied successfully!";
cin.get (); // pause for input
return EXIT_SUCCESS; // program was executed successfully
the reason i used getlocation is to find the path to the file in the first place, in case the file were to be on a different computer and I didn't have the file path.
this is the error: cannot convert `std::string' to `const CHAR*' for argument `1' to `BOOL CopyFileA(const CHAR*, const CHAR*, BOOL)'
alright, now that i've been messing around with this function a little I have another question - It seems I can copy to some locations, but not to all. I run the computer as an administrator, so I'm not sure why it does not copy itself into certain paths. Any thoughts?
im pretty sure im using the 3rd parameter correctly - this way it doesn't overwrite the file if it would already exists. examples of where it doesn't work is in C:\\ as a new file there, or in the startup folder for example - I will test some more in a little
and yet another question to further this program a little more;
i've edited my program a bit and now I want it to generate a name that will always be one larger than the previous, aka the first one named test1.exe the second test2.exe etc.
i thought I coult achieve this with the following code, but i get an error:expected `)' before "i"
Vista does have further permissions than XP. XP was positively unsecured. All of these security facilities have been available since NT 3.5 (3.0 wasn't really used), but largely ingored until recent releases.
"C:\\Users\\test"i".exe" isn't a string. You need to format it using an ostringstream or snprintf.
1 2 3
os << "C:\\Users\\test" << i << ".exe";
std::string filename - os.str();
A application can run at higher privilege than its user. You have to do stuff though.
so i just edited it again, but unfortunately I'm still getting an error.
cannot convert `std::string' to `const CHAR*' for argument `2' to `BOOL CopyFileA(const CHAR*, const CHAR*, BOOL)'
i looked at ostringstream and .str() functions, but couldn't find anything that could resolve that...