windows 在尝试 Process.Start() 之前,如何以编程方式检查文件关联是否存在?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6086973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I programmatically check file that a file association exists before attempting to Process.Start() it?
提问by Andrew
My .Net Windows Forms application generates a PDF report, which I want to show to the user.
我的 .Net Windows 窗体应用程序生成了一个 PDF 报告,我想向用户显示该报告。
Instead of just assuming the client PC has a PDF viewer installed and blindly throwing the PDF at the Operating System to open, is there a way to check against the list of file associations on the clientbeforehand, then show a "you need a PDF viewer application installed - here's a couple of suggestions.." dialog if PDF isn't a registered type?
与其假设客户端 PC 安装了 PDF 查看器并盲目地将 PDF 扔到操作系统上打开,有没有办法事先检查客户端上的文件关联列表,然后显示“你需要一个 PDF 查看器”已安装应用程序 - 这里有一些建议......”对话框,如果 PDF 不是注册类型?
I've found a lot of questions and answers about changing or registering file associations, but I just want an easy way to query the list, not change it.
我发现了很多关于更改或注册文件关联的问题和答案,但我只是想要一种简单的方法来查询列表,而不是更改它。
I'd like a solution that works on Windows XP onwards (WinXP, Vista, Win7).
我想要一个适用于 Windows XP 以后(WinXP、Vista、Win7)的解决方案。
Thanks for your help
谢谢你的帮助
回答by Simon Mourier
It's better not use the registry directly but rely on the Windows API instead. Here is a link on SO that gives a .NET solution: How do I get File Type Information based on extension? (not MIME) in c#
最好不要直接使用注册表,而是依靠 Windows API。这是提供 .NET 解决方案的 SO 上的链接:How do I get File Type Information based on extension? (不是 MIME)在 C# 中
回答by Marino ?imi?
I found there is a .pdf key in the registry, maybe it can help you:
我发现注册表中有一个 .pdf 密钥,也许它可以帮助您:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.pdf]
"Content Type"="application/pdf"
@="AcroExch.Document"
[HKEY_CLASSES_ROOT\.pdf\OpenWithList]
@=""
[HKEY_CLASSES_ROOT\.pdf\OpenWithList\AcroRd32.exe]
@=""
[HKEY_CLASSES_ROOT\.pdf\ShellEx]
[HKEY_CLASSES_ROOT\.pdf\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}]
@="{DC6EFB56-9CFA-464D-8880-44885D7DC193}"