0

When using the Shell32DLL SHFileOperation for file operations, I came across an issue related to moving system file(s) across drives (eg. c:\ to d:).

When moving, the user will be prompted by a system dialog asking "Are you sure you want to move this system file? [Yes, Skip, Cancel]"

Here is the core essence of my move operation:

SHFILEOPSTRUCT struc = new SHFILEOPSTRUCT();
struc.pFrom = fromPtr;
struc.pTo = toPtr;
struc.wFunc = FO_MOVE;
struc.fFlags = 0; // no relevant flags for this
struc.hwnd = 0;
struc.lpszProgressTitle = string.Empty;
struc.fAnyOperationsAborted = false; // initialized to FALSE

int res = SHFileOperation(ref struc);

The operation returns 0x0 i.e. success, but the returned fAnyOperationsAborted is TRUE, even though the user accepted to move the system file. I would expect the operation to return fAnyOperationsAborted=FALSE in that case.

The problem is that I am not able to distinguish between the user accepting, skipping or cancelling the operation, as fAnyOperationsAborted is TRUE in all three cases.

How to solve this issue?

MSDN on SHFileOperation function: https://msdn.microsoft.com/en-us/library/windows/desktop/bb762164(v=vs.85).aspx

1 Answers1

0

Do the FOF_NOCONFIRMATION and/or FOF_NO_UI flags help?

If not you can use IFileOperation instead (Vista+). If you add a sink then IFileOperationProgressSink::PostMoveItem will tell you the HRESULT of each move operation.

Anders
  • 97,548
  • 12
  • 110
  • 164
  • I do want the confirmations, as I want my file explorer to behave like normal Windows Explorer, meaning that FOF_NOCONFIRMATIONS, FOF_NO_UI are not relevant ie. should be kept false – Eigil Jensen Mar 22 '18 at 11:21