pradeep
pradeep

Reputation: 3095

MoveFileEx Problem

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

Answers (3)

plodoc
plodoc

Reputation: 2803

Error 5 is Access Denied. This error may occur if

  • you do not have the right to write in the destination directory
  • you do not have the right to overwrite an existing file with the same name in the destination directory.

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

aJ.
aJ.

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

Vadym Stetsiak
Vadym Stetsiak

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

Related Questions