views:

125

answers:

1

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.

+2  A: 

No happy answers here, Windows Explorer doesn't have an easily way to get it 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.

Hans Passant