开发者

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


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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜