views:

240

answers:

4

I'm attempting to hook into whatever explorer calls when a file is opened (double-click, context menu open, etc.), however I can't figure out which function that is.

Originally, I thought it was ShellExecute, as that does the same thing as far as I can tell, but after hooking into it I learned that it's only used when a new explorer window is opened.

Any ideas which function I should be hooking?

A: 

If you want to intercept these things, just register yourself as the default verb for shell items. Here are some samples.

If you just want to know if someone has change some files you're interested in, you should register for change notifications via FindFirstChangeNotification() and related APIs.

jeffamaphone
We don't want to 'intercept,' we just want notification, assuming by intercept you meant completely overwrite the default behaviour. I considered doing this then passing it off to ShellExecute, but explorer obviously isn't doing that, so it made me a bit weary. We don't want to change the default behavior _at all_.
dauphic
I'm not interested in files being changed. I'm interested in knowing when the user opens the file from explorer.
dauphic
A: 

There are the ShellExecute hooks, but now (after XP) are deprecated because everybody used them for the strangest purposes. Have a look at this for some more detail, and at this for some documentation.

Matteo Italia
Yes, we originally used these. We're trying to find a solution that works on Vista and up, thus a hook to whatever function is called, assuming someone knows which function that is and it's part of a dynamically linked library.
dauphic
A: 

It sounds like the AppInit_DLLs registry key should be good enough.

Make a simple DLL and call the GetCommandLine() in your DllMain function to get the full command line to the application being executed.

Jonas Gulle
There is a simpler way to do this, which involves writing a device driver which can be subscribe for notification of the CreateProcess function. But a plain hook to whatever explorer calls would be our preferred method.
dauphic
A: 

Much simpler than writing a device driver ( but much less amusing ) is the MS research tool detours. Have fun!

TheEruditeTroglodyte

TheEruditeTroglodyte
Detours is useless because I have no idea what function needs to be hooked (though I've concluded that the function isn't exposed from explorer), and would require us to buy a license just to add a very small feature. On top of that, I've already written code to hook functions.
dauphic
Hmmm . . . well that's a tuffy . . . Here's another thought:- Do detours as I suggested- set break point in your code on intercepted file open system call- Look at funcs in stack trace . . .You'd then have the actual func to intercept . . . I've never done this . . don't know if it would work. Maybe not!TheEruditeTroglodyte
TheEruditeTroglodyte