有没有机会从 C# 应用程序中获取驱动器被 TrueCrypt 应用程序加密的信息。其他选项也将非常有帮助。
非常感谢您提前。
[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。