サンプルコード:
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}\shell\open\command";
// 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, string.Empty) as string;
if (!string.IsNullOrEmpty(associatedCmd))
{
Console.WriteLine("\"{0}\" command is associated with {1} extension", associatedCmd, ext);
}
}
}
}
}
出典
2008-08-24 11:01:18
aku
IQueryAssociations –