问题描述
在一个TrueCrypt的容器已被安装到一个驱动器号,是有可能确定在容器中的驱动器盘符是安装从一个批处理文件,或驱动器盘符容器装?
After a TrueCrypt container has been mounted to a drive letter, is it possible to determine in a batch file which container the drive letter was mounted from, or which drive letter the container was mounted to?
在一个批处理文件,我想安装一个特定的TrueCrypt容器到指定的驱动器盘符。 TrueCrypt的错误,如果容器已经安装或如果驱动器盘符不可用,所以我想运行TrueCrypt的只有指定的容器尚未安装到指定的驱动器盘符,也就是说,只有在动作不是招 ŧ已经已经完成。
In a batch file, I want to mount a specified TrueCrypt container to a specified drive letter. TrueCrypt errors if the container is already mounted or if the drive letter isn't available, so I want to run TrueCrypt only if the specified container hasn't already been mounted to the specified drive letter, that is, only if the action hasn't been completed already.
任何建议将是AP preciated。
Any suggestions would be appreciated.
赏金摘要总之想象你有卷 C:\\ Vol1.tc
和 C:\\ Vol2.tc
安装的驱动器 X
和是
。你怎么能说电话 C:\\ Vol1.tc
安装驱动 X
和Ç :\\ Vol2.tc
驱动是
programaticaly一个批处理文件或C#code
Bounty Summary In short imagine you have volumes C:\Vol1.tc
and C:\Vol2.tc
mounted to drives X
and Y
. How can you tel that C:\Vol1.tc
is mounted to drive X
and C:\Vol2.tc
to drive Y
programaticaly with a batch file or C# code?
推荐答案
这样做会直接问到TrueCrypt的司机自己的一种方式。
这可能是与DeviceIoControl函数来实现。
事实上,这正是TrueCrypt的图形用户界面在做什么。
A way to do that would be to directly ask to Truecrypt driver himself.This could be achieved with the DeviceIoControl function.In fact, that's exactly what the TrueCrypt GUI is doing.
请注意,它更容易做,在C ++中。
的好文章。
Note that it's easier to do that in c++.You'll find a good article here.
我们的想法是调用的DeviceIoControl
功能,请求对 TC_IOCTL_GET_MOUNTED_VOLUMES
您将获得的结构,与所有已安装的卷路径和驱动器号。
实际上这是一个26元件阵列(每个可能的驱动器号),称为wszVolume,它含有装在TrueCrypt的体积的路径。
The idea is to call the DeviceIoControl
function, asking for the TC_IOCTL_GET_MOUNTED_VOLUMES
You will obtain a structure, with all of the mounted volumes path and drive letters.In fact it's a 26 elements array (one for each possible drive letter), called wszVolume, which contain the path of the truecrypt volume which is mounted on.
希望下面的示例将帮助您找到如何在你的情况做的。
Hope the following sample will help you find how to do in your case.
样品code在C#中:
class Program
{
static void Main(string[] args)
{
uint size = (uint)Marshal.SizeOf(typeof(MOUNT_LIST_STRUCT));
IntPtr buffer = Marshal.AllocHGlobal((int)size);
uint bytesReturned;
IntPtr _hdev = CreateFile("\\\\.\\TrueCrypt", FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
bool bResult = DeviceIoControl(_hdev, TC_IOCTL_GET_MOUNTED_VOLUMES, buffer, size, buffer, size, out bytesReturned, IntPtr.Zero);
MOUNT_LIST_STRUCT mount = new MOUNT_LIST_STRUCT();
Marshal.PtrToStructure(buffer, mount);
Marshal.FreeHGlobal(buffer);
for (int i = 0; i < 26; i++)
Console.WriteLine("{0}: => {1}", (char)('A' + i), mount.wszVolume[i]);
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
class MOUNT_LIST_STRUCT
{
public readonly UInt32 ulMountedDrives; /* Bitfield of all mounted drive letters */
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 26)]
public readonly MOUNT_LIST_STRUCT_VOLUME_NAME[] wszVolume; /* Volume names of mounted volumes */
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 26)]
public readonly UInt64[] diskLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 26)]
public readonly int[] ea;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 26)]
public readonly int[] volumeType; /* Volume type (e.g. PROP_VOL_TYPE_OUTER, PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED, etc.) */
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
struct MOUNT_LIST_STRUCT_VOLUME_NAME
{
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.I2, SizeConst = 260)]
public readonly char[] wszVolume; /* Volume names of mounted volumes */
public override string ToString()
{
return (new String(wszVolume)).TrimEnd('\0');
}
}
public static int CTL_CODE(int DeviceType, int Function, int Method, int Access)
{
return (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2)
| (Method));
}
private static readonly uint TC_IOCTL_GET_MOUNTED_VOLUMES = (uint)CTL_CODE(0x00000022, 0x800 + (6), 0, 0);
[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true, CharSet = CharSet.Auto)]
static extern bool DeviceIoControl(IntPtr hDevice, uint dwIoControlCode,
IntPtr lpInBuffer, uint nInBufferSize,
IntPtr lpOutBuffer, uint nOutBufferSize,
out uint lpBytesReturned, IntPtr lpOverlapped);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr CreateFile(
[MarshalAs(UnmanagedType.LPTStr)] string filename,
[MarshalAs(UnmanagedType.U4)] FileAccess access,
[MarshalAs(UnmanagedType.U4)] FileShare share,
IntPtr securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero
[MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
[MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
IntPtr templateFile);
}
这篇关于确定安装的TrueCrypt卷的驱动器盘符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!