Board index » delphi » Intercepting a windows message

Intercepting a windows message

Is there a straight forward way to know when a particular application is
about to start?  What I want to do is to create a list of certain .exe files
and when any ont of them is executed I want to run some code that changes
particular settings according to which application is starting.

Can I do that by intercepting a windows message signalling the start of an
application (if so how?) or is there a better way to do it?

The .exe applications are commercial programs - nothing I wrote.

 

Re:Intercepting a windows message


Quote
Lorne wrote:
> Is there a straight forward way to know when a particular application
> is about to start?  

No. There isn't even a non-straightforward way <g>.

--
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

Re:Intercepting a windows message


Quote
> Is there a straight forward way to know when a particular application is
> about to start?  What I want to do is to create a list of certain .exe files
> and when any ont of them is executed I want to run some code that changes
> particular settings according to which application is starting.

Do you need to change the settings before the application is started or
later, for example when a window is shown or activated? Latter is
possible, take a look at system wide CBT hooks (or maybe message hooks).

--
Jens Gruschel
http://www.pegtop.net

Re:Intercepting a windows message


Quote
"Jens Gruschel" <nos...@thisurldoesnotexist.com> wrote in message

news:4741d659$1@newsgroups.borland.com...

Quote
>> Is there a straight forward way to know when a particular application is
>> about to start?  What I want to do is to create a list of certain .exe
>> files and when any ont of them is executed I want to run some code that
>> changes particular settings according to which application is starting.

> Do you need to change the settings before the application is started or
> later, for example when a window is shown or activated? Latter is
> possible, take a look at system wide CBT hooks (or maybe message hooks).

> --
> Jens Gruschel
> http://www.pegtop.net

I can live with do it after the aplication starts, just need an idiots guide
to CBT hooks as I have not been able to work out what to do from what I have
found so far !  Have you any links?

Re:Intercepting a windows message


Quote
"Lorne" <lorne_ander...@hotmail.com> wrote in message

news:47420490$1@newsgroups.borland.com...

Quote
> I can live with do it after the aplication starts, just need
> an idiots guide to CBT hooks

System Hooks are not for the feint of heart, especially when hooking
external processes.  You can severely impact system performance and
stability if you use a hook incorrectly.

Quote
> I have not been able to work out what to do from what
> I have found so far !

Since you want to hook other applications, you must implement the hook
inside a DLL and have it send the relevant information back to your main app
when triggered.  Look at the SetWindowsHookEx() function for more
information.  Go to http://www.deja.com and search through the newsgroup
archives for past examples.

Gambit

Re:Intercepting a windows message


Quote
Lorne wrote:
> Is there a straight forward way to know when a particular application is
> about to start?  What I want to do is to create a list of certain .exe files
> and when any ont of them is executed I want to run some code that changes
> particular settings according to which application is starting.

> Can I do that by intercepting a windows message signalling the start of an
> application (if so how?) or is there a better way to do it?

> The .exe applications are commercial programs - nothing I wrote.

Suppose you want to catch executions of foo.exe. Write your program like
this:

program foo;
begin
   ChangeSettings;
   CreateProcess('original-foo.exe');
end.

In your program's installer, do this:

rename foo.exe original-foo.exe
copy \install-folder\foo.exe .

Now, whenever anyone runs foo.exe, it'll be your program instead of the
original.

This might break things, though. Programs don't usually like to have
different names. You might have to just replace all the shortcuts and
file associations in the user's environment. If someone directly runs
foo.exe from a command prompt, then the settings won't get changed, but
any of the "normal" ways of invoking the program will be covered.

--
Rob

Other Threads