0

I'd like to have a program that runs in the background, listens for any file transfers, and then cancels explorer's file transfer mechanism, and starts it's own.

How do I do this? Is there some dll that I can pinvoke?

Why?

  • To filter files of certain types along the way. (automatically, or with a prompt.)
  • A "no to all" duplicate transfers option.
  • Logging.
  • To not have to start the program up every time I want to transfer files.
  • To further understand what's going on under the hood.
  • To not rely on third party programs.
  • Any additional features I think of in the future.

* By file transfers I mean moving/copying files/folders via drag and drop, but I am only concerned with file transfers from disk to disk, not from the internet.

user420667
  • 6,552
  • 15
  • 51
  • 83

2 Answers2

5

Define "file transfer".

Do you want to sniff for ftp, http requests? Explorer copies as well? Local only or on the network?

I think this is bound to get brittle. Your best bet would be if explorer let's you hook into file copy operations via a shell extension. I'm not sure whether it can be done.

See The Complete Idiot's Guide to Writing Shell Extensions for a starting point.

See also http://msdn.microsoft.com/en-us/library/cc144063(v=vs.85).aspx

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thx Robert, that is elegant of you to add – sehe May 06 '11 at 20:36
  • Could you elaborate on what you mean by "it's bound to get brittle" or why "this is going to finish bad"? – user420667 May 06 '11 at 21:54
  • 1
    You are trying to modify the OS. This will only work if the OS was designed to let you do that. The closest you can come is hooking Explorer; still that won't get you `control over file transfers` in general, since there will be transfers that won't trigger the hook. Moreover, there will be border cases in which the hook doesn't do what you want or interferes badly with other software (say, when your virus scanner wants to quarantaine a file, you don't want the hook to trigger). **In short**: if this is a security critical part, don't do it. Is it convenience, go for the `ICopyHook` option – sehe May 06 '11 at 21:58
3

Before I start: This is going to finish bad, but nevertheless:

For Vista/7:

You need to Hook (Hooking)

To CoCreateInstance of IFileOperation and then change what you need from there.

This won't work on XP however, and is probably so fragile that will work on some PCs and not on others because there are millions of ways to do the same thing on windows from the API perspective.

Marino Šimić
  • 7,318
  • 1
  • 31
  • 61
  • +1 Hear hear. This is the second day in a row where I've seen an answer of yours with a prophetically `true` quality to it -- yet I can't prove it ([see here for the other one](http://stackoverflow.com/questions/5899274/shuffle-list-with-some-conditions/5904381#5904381)) – sehe May 06 '11 at 20:39
  • you know I actually coded that thingy? I have it at work, the most complex part was creating the recursion on the insertion in the graph. I think there still is a bug somewhere. Monday I'll post it there if I dont forget. – Marino Šimić May 06 '11 at 20:42
  • I like fiddling with algoritms more than properly coding, just for the fun of proving my assumptions correct. Like this two hour time waste here http://stackoverflow.com/questions/5909031/fast-2d-illumination-algorithm/5915431#5915431 – Marino Šimić May 06 '11 at 20:49