- 编辑 - 我觉得自己像个白痴.我有一种感觉,下面的答案会起作用,但没有看到任何谷歌的结果类似于下面的答案.所以,当我看到这个复杂的代码时,我认为它必须是这样的.
我搜索并发现这个Windows:列表和启动应用程序与扩展程序相关但是它没有回答我的问题.通过下面的调整,我提出了以下内容.但它会卡在图像文件上.Txt文件运行正常
我将尽快更新此代码以考虑带有空格的应用程序路径,但我不明白为什么图像文件不启动.
static void launchFile(string fn)
{
//majority was taken from
//https://stackoverflow.com/questions/24954/windows-list-and-launch-applications-associated-with-an-extension
const string extPathTemplate = @"HKEY_CLASSES_ROOT\{0}";
const string cmdPathTemplate = @"HKEY_CLASSES_ROOT\{0}\shell\open\command";
string ext = Path.GetExtension(fn);
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, string.Empty) as string;
if (!string.IsNullOrEmpty(associatedCmd))
{
//Console.WriteLine("\"{0}\" command is associated with …Run Code Online (Sandbox Code Playgroud)