Process.Start set FileActivatedEventArgs.NeighboringFilesQuery

Marcel Lorenz 86 Reputation points
2021-01-12T16:35:20.423+00:00

When I want to open a file with its default application I simply use:

ProcessStartInfo startInfo = new ProcessStartInfo() {  
    FileName = filePath,  
    WorkingDirectory = new FileInfo(filePath).DirectoryName  
};  
  
Process.Start(startInfo);  

But there is a problem: When I play an MP4 file from a directory within the windows explorer, the file is opened using Microsoft Movies & TV. But also the app gets information about other files in the same directory because there is the possibility to go to the next video. This only works when I am in the given directory inside the windows explorer when opening. When I use for example quick access to open the file I cannot go to other files although there are other videos inside the directory.

I created a blank console app to print all the parameters and then I opened an MP4 file with it:

static void Main(string[] args) {  
    Console.WriteLine(args.Length);  
    Console.WriteLine();  
  
    foreach (string s in args)  
        Console.WriteLine(s);  
  
    Console.ReadKey();  
}  

But no matter where I open this app from (within the directory, quick access), it always outputs:

1  
  
D:\Videos\Video1.mp4  

So the same parameters lead to different app behavior.

So where does this additional information come from and how to add it using Process.Start? Is there something registered within the registry which parameters should be passed to a given app? If so, how to get this information?

Edit:
Okay, I found the reason. It's the FileActivatedEventArgs.NeighboringFilesQuery. Now there is the question of how to pass this query when starting the process

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,020 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.