Is there any chance to get from C# application the information which drives were encrypted by TrueCrypt application. Other options would be also very helpful.
Thank you very much in advance.
Is there any chance to get from C# application the information which drives were encrypted by TrueCrypt application. Other options would be also very helpful.
Thank you very much in advance.
Yes. When using this code (based on code found at 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);
}
The variable targetPath in this scenario contains the value \Device\TrueCryptVolumeN.
When passing the C:\ in as the path, the value of targetPath is \Device\HarddiskVolume1.