FOF_SILENT w/ SHFileOperation not allowed when run from USB on SP3?

Hello everyone,

I seem to have hit an undocumented security precaution only found in Windows XP SP3, and I want to make sure that I’m not mistaken and perhaps some other factor is to blame.

I have an EXE that calls SHFileOperation to perform a recursive file copy (yes, I’m lazy, best code is the least code, and so on and so forth) from the same directory to the local system drive.

The call to SHFileOperation works fine if the EXE is run from the local disk, but fails only if the EXE is on the USB disk, with ERROR_CANCELLED.

However, if I remove the FOF_SILENT from the call to SHFileOperation, the call succeeds regardless of where the EXE is being run from. I can’t find any reference to this anywhere, but it does seem like it could be a security “improvement” in SP3. Note that all code is being run as an administrator (it’s a setup) and so it’s not a permissions issue.

IF it is a security thing, I don’t see the benefit - any coder worth his salt can write a recursive file copy using core WIN32 APIs. But I don’t see any other reason an invisible write would fail, while a user-visible write would succeed. So color me confused.

Has anyone come across this issue before and is there any way other than (a) writing a recursive FileCopy function, or (b) launching said exe with SW_HIDE to get around this anyway? And if this indeed an attempt at security, does any have idea why MS would do something this futile and pointless, hindering only well-meaning developers?

(FYI The code runs fine on Vista and 7 as an administrator with elevated UAC privileges.)

wrote in message news:xxxxx@ntdev…

> However, if I remove the FOF_SILENT from the call to SHFileOperation, the
> call succeeds regardless of where the EXE is being run from.

Do you see any popups/prompts without FOF_SILENT ? If not - just remove
FOF_SILENT ?

> (FYI The code runs fine on Vista and 7 as an administrator with elevated
> UAC privileges.)

Then perhaps it is just a bug in XP, fixed in Vista+.

– pa

There is a progress dialog shown when FOF_SILENT is removed, but no blocking input dialogs or message boxes.

If it’s a bug, then it was only introduced in SP3… and I confess I’m at a loss as to how it could arise “organically.”

I must apologize for the missing words in the penultimate sentence of the original message - I was called away from my workstation several times during its composition and my brain somehow filled in the gaps when I reread it quickly.

How do you make the source and destination file name strings?

Here’s a complete code sample: https://gist.github.com/1290539

But I assume you’re asking about either the asterisk at the end of the source path or the double-null termination of both source and destination strings - they’re both there.