I am working on an application that uses a Mutex to ensure that it is the only instance of the application running on the system.
When another instance of the application attempts to start, I want a method to run in the original instance.
Can I invoke a specific method in my application from another instance of the application?
I’ve found some examples using RegisterWindowMessage/PostMessage Win32 APIs by sending the message to HWND_BROADCAST, but I couldn’t get them to work, and I’ve read elsewhere that using HWND_BROADCAST can be dangerous.
Is there a better way to do this that doesn’t involve the app needing to be run in privileged mode?
Here’s a little helper I wrote.
To use it:
From another process:
Note that it uses the full name of the PipeListener as the default name of the pipe. If you need to get more discrete than that, use the constructor overload that takes a pipe name.
Here’s the class: