Reputation: 3095
int i ;
DWORD dw ;
String^ Source = "c:\\Program\\test.exe" ;
String^ Destination = "c:\\Program Files" ; // move to program Files Folder
//pin_ptr<const wchar_t> WSource = PtrToStringChars(Source);
// pin_ptr<const wchar_t> WDestination = PtrToStringChars(Destination);
i = MoveFileEx(L"c:\\Program Files\\Program\\Test.exe",L"c:\\Program Files",MOVEFILE_REPLACE_EXISTING) ;
dw = GetLastError() ;
return 0;
The status dw is valued as 5 , when i run the program.
Whats the error
Upvotes: 1
Views: 4297
Reputation: 2803
Error 5 is Access Denied. This error may occur if
I think you are in the second case: the file you want to overwrite is locked. This it is an executable, it may be running.
Upvotes: 0
Reputation: 35450
Error code 5 is Access Denied. Please check if you have enough permissions for destination directory.
BOOL WINAPI MoveFileEx(
__in LPCTSTR lpExistingFileName,
__in_opt LPCTSTR lpNewFileName,
__in DWORD dwFlags
);
MOVEFILE_REPLACE_EXISTING
-- This value cannot be used if lpNewFileName or lpExistingFileName names a directory.
In your case the destination is "C:\Program files" a directory. So it fails.
Upvotes: 3
Reputation: 1972
Type in command prompt net helpmsg 5. This will show you the meaning of the error. In my system it is: "Access is denied.".
Just a hint: why second parameter is not a file path?
Upvotes: 3