0

有没有机会从 C# 应用程序中获取驱动器被 TrueCrypt 应用程序加密的信息。其他选项也将非常有帮助。

非常感谢您提前。

4

1 回答 1

0

是的。使用此代码时(基于https://social.msdn.microsoft.com/Forums/en-US/e43cc927-4bcc-42d7-9630-f5fdfdb4a1fa/get-absolute-path-of-drive-mapped-到本地文件夹?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。

于 2015-05-28T14:19:27.730 回答