是否可以获取由TrueCrypt加密的驱动器的信息



是否有机会从C#应用程序获取由TrueCrypt应用程序加密的驱动器的信息。其他选择也将非常有帮助。

提前非常感谢你。

是的。 使用此代码时(基于 https://social.msdn.microsoft.com/Forums/en-US/e43cc927-4bcc-42d7-9630-f5fdfdb4a1fa/get-absolute-path-of-drive-mapped-to-local-folder?forum=netfxnetcom 中的代码):

[DllImport("kernel32.dll")]
private static extern uint QueryDosDevice(string lpDeviceName, StringBuilder lpTargetPath, int ucchMax);
public static bool IsTrueCryptVolume(string path, out StringBuilder lpTargetPath)
{
    bool isTrueCryptVolume = false;
    if (String.IsNullOrWhiteSpace(path))
    {
        throw new ArgumentException("path");
    }
    string pathRoot = Path.GetPathRoot(path);
    if (String.IsNullOrWhiteSpace(pathRoot))
    {
        throw new ArgumentException("path");
    }
    string lpDeviceName = pathRoot.Replace("\", String.Empty);
    lpTargetPath = new StringBuilder(260);
    if (0 != QueryDosDevice(lpDeviceName, lpTargetPath, lpTargetPath.Capacity))
    {
        isTrueCryptVolume = lpTargetPath.ToString().ToLower().Contains("truecrypt");
    }
    return isTrueCryptVolume;
}
static void Main(string[] args)
{
    StringBuilder targetPath;
    var isTrueCryptVolume = IsTrueCryptVolume("N:\", out targetPath);
}

此方案中的变量 targetPath 包含值 \Device\TrueCryptVolumeN。

传递 C:\ 时作为路径,targetPath 的值为 \Device\HarddiskVolume1。

最新更新