automaticDestinations-ms文件和customDestinations-ms有什么区别?不安装WindowsAPICodePack库的情况下它们如何用C#读取和解密?请给出详细代码
.automaticDestinations-ms和.customDestinations-ms是Windows操作系统中的两种不同类型的文件。它们用于存储任务栏和开始菜单的快捷方式和最近使用的文件列表。
.automaticDestinations-ms文件存储了用户最近打开或操作的文件和程序的快捷方式。而.customDestinations-ms文件则包含了用户自定义的任务栏和开始菜单的快捷方式。
要读取和解密这些文件,我们可以使用WindowsAPICodePack库。该库提供了访问Windows Shell的功能,包括访问.automaticDestinations-ms和.customDestinations-ms文件的能力。
以下是一个使用C#读取和解密这些文件的示例代码:
using Microsoft.WindowsAPICodePack.Shell;
using System;
using System.IO;
namespace ReadDestinationsFiles
{
class Program
{
static void Main(string[] args)
{
// 指定.automaticDestinations-ms文件路径
string automaticDestinationsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
@"Microsoft\Windows\Recent\AutomaticDestinations");
// 指定.customDestinations-ms文件路径
string customDestinationsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
@"Microsoft\Windows\Recent\CustomDestinations");
// 读取.automaticDestinations-ms文件
using (ShellObject automaticDestinations = ShellObject.FromParsingName(automaticDestinationsPath))
{
// 解密文件
ShellContainer decryptedContainer = (ShellContainer)automaticDestinations;
decryptedContainer.Thumbnail.FormatOption = ShellThumbnailFormatOption.ThumbnailOnly;
// 遍历文件夹中的所有项目
foreach (ShellObject shellObject in decryptedContainer)
{
// 获取项目的路径
string path = shellObject.ParsingName;
Console.WriteLine(path);
}
}
// 读取.customDestinations-ms文件
using (ShellObject customDestinations = ShellObject.FromParsingName(customDestinationsPath))
{
// 解密文件
ShellContainer decryptedContainer = (ShellContainer)customDestinations;
decryptedContainer.Thumbnail.FormatOption = ShellThumbnailFormatOption.ThumbnailOnly;
// 遍历文件夹中的所有项目
foreach (ShellObject shellObject in decryptedContainer)
{
// 获取项目的路径
string path = shellObject.ParsingName;
Console.WriteLine(path);
}
}
}
}
}
注意,上述代码需要引用"Microsoft.WindowsAPICodePack"和"Microsoft.WindowsAPICodePack.Shell"命名空间,并在项目中添加对WindowsAPICodePack库的引用。此外,还需要将.automaticDestinations-ms和.customDestinations-ms文件的路径替换为实际的文件路径
原文地址: https://www.cveoy.top/t/topic/infs 著作权归作者所有。请勿转载和采集!