获取Windows Media Center库中包含的目录

我正在为Media Center(Windows 7附带的版本)编写一个加载项,并希望检索用户已包含在媒体库中的物理目录列表(图片,video,录制的电视,电影,音乐) 。

Media Center对象模型( Microsoft.MediaCenter.* )似乎没有任何规定来获取此信息。

注册表在HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Media Center\MediaFolders有一个键,但这些键始终为空。

%userprofile%\AppData\Local\Microsoft\Media Player\wmpfolders.wmdb似乎有完整的目录列表,但无法分辨每个目录与哪个媒体库相关,因为这些是Media的设置玩家,他们的存在可能只是巧合。

有谁知道如何可靠地检索这些目录的列表,最好是从加载项程序集中(即使用C#)?

我使用Reflector在ehshell如何做到这一点上达到顶峰。 对于图片,video,音乐和录制的电视,它使用的是ehuihlp.dll的导入方法。 对于电影,它只是直接从HKCR\Software\Microsoft\Windows\CurrentVersion\Media Center\MediaFolders\Movie提取列表。

以下是如何使用导入方法的示例:

using System.Runtime.InteropServices ;

 [DllImport(@"c:\Windows\ehome\ehuihlp.dll", CharSet = CharSet.Unicode)] static extern int EhGetLocationsForLibrary(ref Guid knownFolderGuid, [MarshalAs(UnmanagedType.SafeArray)] out string[] locations); 

 Guid RecordedTVLibrary = new Guid("1a6fdba2-f42d-4358-a798-b74d745926c5"); Guid MusicLibrary = new Guid("2112ab0a-c86a-4ffe-a368-0de96e47012e"); Guid PicturesLibrary = new Guid("a990ae9f-a03b-4e80-94bc-9912d7504104"); Guid VideosLibrary = new Guid("491e922f-5643-4af4-a7eb-4e7a138d8174") 

 string[] locations; EhGetLocationsForLibrary(ref PicturesLibrary, out locations); 
 private void ListItems(ListMakerItem listMakerItem) { if (listMakerItem.MediaTypes == Microsoft.MediaCenter.ListMaker.MediaTypes.Folder) { // Recurse into Folders ListMakerList lml = listMakerItem.Children; foreach (ListMakerItem listMakerChildItem in lml) { ListItems(listMakerChildItem); } } else { BuildDirectoryList(listMakerItem.FileName) } } private void BuildDirectoryList(string fileName) { // Parse fileName and build unique directory list } 

这是一种间接方式,但可以使您构建所需的目录列表。 有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/ee525804.aspx 。