.net – Windows:列出并启动与扩展名关联的应用程序
发布时间:2020-12-13 20:19:14 所属栏目:Windows 来源:网络整理
导读:如何确定与特定扩展(例如.JPG)相关联的应用程序,然后确定该应用程序的可执行文件所在的位置,以便可以通过调用System.Diagnostics.Process.Start(…)启动它. 我已经知道如何读写注册表.注册表的布局使得更难以标准方式确定哪些应用程序与扩展相关联,显示名称
如何确定与特定扩展(例如.JPG)相关联的应用程序,然后确定该应用程序的可执行文件所在的位置,以便可以通过调用System.Diagnostics.Process.Start(…)启动它.
我已经知道如何读写注册表.注册表的布局使得更难以标准方式确定哪些应用程序与扩展相关联,显示名称以及可执行文件所在的位置.
示例代码:
using System; using Microsoft.Win32; namespace GetAssociatedApp { class Program { static void Main(string[] args) { const string extPathTemplate = @"HKEY_CLASSES_ROOT{0}"; const string cmdPathTemplate = @"HKEY_CLASSES_ROOT{0}shellopencommand"; // 1. Find out document type name for .jpeg files const string ext = ".jpeg"; var extPath = string.Format(extPathTemplate,ext); var docName = Registry.GetValue(extPath,string.Empty,string.Empty) as string; if (!string.IsNullOrEmpty(docName)) { // 2. Find out which command is associated with our extension var associatedCmdPath = string.Format(cmdPathTemplate,docName); var associatedCmd = Registry.GetValue(associatedCmdPath,string.Empty) as string; if (!string.IsNullOrEmpty(associatedCmd)) { Console.WriteLine(""{0}" command is associated with {1} extension",associatedCmd,ext); } } } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – 线程ID与线程句柄
- 使用SWAGGER-UI中的Windows身份验证调用WCF
- 如何在Windows上修补?
- windows-8 – Visual Studio Express 2012 for Desktop中没
- 电子邮件 – 如何从Windows命令行安装Exchange邮件存储?
- windows下编译 libjpeg以及libjpeg-turbo
- win-universal-app – Windows 10的应用内存限制是什么?
- windows – 如何在Chrome中启用ActiveX?
- Windows10 版本说明 From wiki 20190104
- windows下Tomcat指定jdk并部署到系统服务设置开机启动
推荐文章
站长推荐
- 如何在Windows上将Ruby添加到PATH变量中?
- windows-server-2008-r2 – 虚拟音频电缆在Windo
- windows – DNS – 从旧服务器重定向到新服务器
- 调试 – 在Windows Server 2003中创建进程的内存
- Windows Phone 8.1 cordova下拉列表无法正常工作
- 页面文件应该与内存量相关的大小(在Windows Serv
- 如何在Windows 7上安装带有Python支持的GDB
- windows-server-2008-r2 – 禁止,减慢或停止对RD
- 如何使Windows文件锁定更像UNIX文件锁定?
- 用于Windows 8.1 / Windows 10的C#中的Cordova插
热点阅读