0

Open the file with the associated application if there is an app opened, bring it to the frontend, and open the file.

I wrote an app associated with specified file extensions. Double click the extension file and launch the app through registry

# location HKEY_CLASSES_ROOT\MyApp.Bif\shell\open\command

"C:\Users\alpha\AppData\Roaming\MyCompany\MyApp.exe" "%1"

Now I hope the file can be opened by an opened application. Then bring the app to the front end and be focused.

The only way I thought is:

  1. open a new app.
  2. check is there any opened app?
  3. if no, open the file.
  4. if yes, notify it to open the file, close itself.
  • notify it: tcp? namedpipe?

There is a common function, is there any direct method?

Thanks in advance.

Lance U. Matthews
  • 15,725
  • 6
  • 48
  • 68
Echo
  • 183
  • 2
  • 11
  • It'd be helpful if you tagged the question with what kind of application `MyApp.exe` is ([tag:console-application], [tag:WinForms], [tag:WPF], etc.). It sounds like you want it to be a [single-instance application](https://stackoverflow.com/q/184084/150605). – Lance U. Matthews Nov 19 '21 at 03:55
  • It's going to be difficult to programmatically determine "is this file already open by a running application.". I think you want to just invoke [ShellExecute](https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew) on the file. Most apps have logic to bring themselves to the foreground if already running. Just rely on that to work. – selbie Nov 19 '21 at 07:04

0 Answers0