0

TrueCrypt アプリケーションによって暗号化されたドライブの情報を C# アプリケーションから取得する機会はありますか。他のオプションも非常に役立ちます。

事前にどうもありがとうございました。

4

1 に答える 1

0

はい。このコードを使用する場合 ( 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 です。

于 2015-05-28T14:19:27.730 に答える