This article mainly introduces the PowerShell implementation query to open a file default application, this article through C # call Windows API to achieve this requirement, the need for friends can refer to the
Many file extensions are bound to an executable application. That's why you can use Invoke-item to open a document.
It is not troublesome to find a file with a given suffix name that is opened by that default reference program. We can use the registry in the Windows system to programmatically resolve it. However, when scanning the registry, a little attention to the 32-bit and 64-bit machine problems, this is not the focus of this article.
Another way, slightly heterodoxy, calls the Windows API. The following example shows how to invoke the. The biggest advantage in taking this approach is the ability to borrow in the operating system. And your cost is only indirectly calling the functions in the Windows API with C # code:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 The |
|
The only limitation is that the file that findexecutable () needs to be checked is present, and you cannot request it only with the file name extension.
In addition, @reidca feedback said that the method could not detect files opened by an MMC add-in, such as a CER and a PFX certificate file, and the program would crash.