Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open program once with multiple files as arguments from explorer

I have a program that works when, a file is opened with it using the right click menu in explorer. But if I select multiple files and then right click and open with my program then it opens multiple instances of my program, instead of just passing the multiple files as arguments to a single instance. The program is written in vb.net but is not a windows form, it is just a module, so I can to tick the Single instance option in the properties in Visual Studio.

So how do I open multiple files from explorer context menu in a single instance.

like image 441
Jonathan. Avatar asked Jan 22 '23 04:01

Jonathan.


1 Answers

No happy answers here, Windows Explorer doesn't provide an easy way to start your program passing all selected files. That requires a shell context menu handler, they are very difficult to write in managed code. And up to .NET 4.0 could not be safely written.

It is nevertheless easy to simulate it with the application framework available in VB.NET, make your app a singleton and implement the StartupNextInstance event. The only issue is that this is not particularly fast. And that it doesn't work in console mode apps.

like image 57
Hans Passant Avatar answered May 08 '23 16:05

Hans Passant