Why Process.Start (string) returns null for WMV file
So I have a WMV video file:
var fileName = @"C:\MyFolder\MyVideo.WMV"
and I start the video and get my process id with the code:
var process = Process.Start(fileName);
if (process != null)
{
processId = process.Id;
}
Although my video file starts, process
it is always null.
From Process.Start (string) MSDN I see that:
Return Value Type:
System.Diagnostics.Process
The new process that is associated with the process resource, or null if no process resource is started. Note that a new process that has already started running instances of the same process will be independent of others. In addition, Start can return a non-null process with its ProcessHasExited property already set to true. In this case, the process may have activated an existing instance of itself and then exited.
It says null is returned if no new process is started. But my process has started and null hasn't returned yet. Why is this?
source to share
Because you cannot "run a WMV file". In your scenario, you rely on the OS file extension handler mappings to invoke the default application to handle it.
UPDATE
In the MSDN docs:
Use this overload to start a process resource by specifying its file name. The overload binds the resource to the new process component. If the process is already running, no additional process starts the resource. Instead, the existing process resource is reused and no new process component is created. In such a case, instead of returning a new Process component, Start returns null to the calling Procedure.
Is it possible that some OS gizmo responsible for directing your media content request to the registered extension app is already running? I would say probably since logically it would be explorer.exe which is always up.
UPDATE 2
Here is a screenshot from SysInternals after starting playing a WMV file using Process.Start:
As you can see, wmplayer opens under svchost.exe, so at the time you requested the WMV file svchost was already running, so Start returns null as per design. PPT, or rather PowerPoint, will open in a separate process, not under svchost's control.
source to share