So I wrote a context menu shell extension. Its purpose is to inspect an image file's contents and then rename the file based on its findings. The shell-extension part works fine.

When it attempts to rename the file, however, the operation fails. The file is reported as being in use. Presumably it is Explorer locking the file; probably thumbnail-generation or something since it's image files involved. Since the file has to be selected in order to bring up its right-click menu there's really no way around that.

Initially I used MoveFile. Then I tried SHFileOperation. Then I tried to get the IShellFolder of the containing directory and use its SetNameOf function. None of them worked, though in the case of SetNameOf it might have been an error on my part, what with all the extra layers the IShellFolder approach introduced.

Does anyone have any suggestions? Like how to get Explorer to do the rename for me (via IShellFolder or who knows what else), or how to get Explorer to "let go" of the file for a moment so I can rename it?