hello guys i have one simple program which copying itself. Its work great when i copying in D disk. But when im trying to copy it on c disk nothing happens.
This is code :
int main()
{
string appDir = "";
appDir = std::string( result, GetModuleFileName( NULL, result, MAX_PATH ) );
CopyFile(appDir.c_str(), "C:\\SelfCopyingApp.exe", 1);
system("PAUSE");
return 0;
}
Does anyone have an idea?
Thanks…
By default, the system drive has locked down permissions which prevent anyone from copying things there who are not administrators. Generally, one should not be messing with the root of the drive. If you need to do something like an installer, then you should
%PROGRAMFILES%\CompanyName\ProductNameMessing with the root of the drive is asking for trouble; that’s not where programs go.
Other notes on this code not related to your question:
system("pause")is wrong. Usestd::cin.get()if you really want a portable way to get that behavior.GetModuleFileNamefails you’re going to be copying some random garbage to that location, not yourself. You need to check the return codes andGetLastErrorcodes of every Win32 function.