是否有机会从C#应用程序获取由TrueCrypt应用程序加密的驱动器信息。其他选项也非常有用。
非常感谢你。
答案 0 :(得分: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:\ in作为路径时,targetPath的值为\ Device \ HarddiskVolume1。