tags:

views:

34

answers:

3
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

+1  A: 

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?

Vadmyst
I want to move the test.exe to Program Files Folder
rajivpradeep
Verify that test.exe is not used by any application. And that it is not running (via Task Manager). Then try to move that file manually in the explorer (this will verify that currently logged user has the rights to move the file).
Vadmyst
+1  A: 

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.

aJ
I am running in admin mode, i think it's not the problem with permissions
rajivpradeep
"c:\\Program Files\\Test.exe" , i did this but it's not coming..!!
rajivpradeep
A: 

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.

plodoc
ya, i think this is the problem. What should i do..?
rajivpradeep
You can rename the executable, the copy the new version and ask to delete the old one at reboot (with MoveFileEx(oldfile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT)
plodoc