PowerShell implementation query opens a file's default application

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.