Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 闪存驱动器成像_C#_Usb - Fatal编程技术网

C# 闪存驱动器成像

C# 闪存驱动器成像,c#,usb,C#,Usb,我想写一个应用程序,将创建一个“图像”的闪存驱动器。这包括驱动器的总体布局,而不仅仅是文件。因此,如果驱动器为4GB,则会得到4GB文件。这可能吗?如果可能的话,有人能告诉我如何实现这一目标的信息方向吗 您是否尝试过将驱动器作为文件打开并复制它?您是否尝试过将驱动器作为文件打开并复制它?这是可能的。我这样做是为了一个内部应用,所以我不能只是粘贴它的源代码,但我可以给你一些提示。你将不得不调用一些东西 [DllImport("kernel32.dll", CharSet = CharSet.Uni

我想写一个应用程序,将创建一个“图像”的闪存驱动器。这包括驱动器的总体布局,而不仅仅是文件。因此,如果驱动器为4GB,则会得到4GB文件。这可能吗?如果可能的话,有人能告诉我如何实现这一目标的信息方向吗

您是否尝试过将驱动器作为文件打开并复制它?

您是否尝试过将驱动器作为文件打开并复制它?

这是可能的。我这样做是为了一个内部应用,所以我不能只是粘贴它的源代码,但我可以给你一些提示。你将不得不调用一些东西

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "CreateFileW", SetLastError = true)]
public static extern IntPtr CreateFile(string name, int access, int share, byte[] attributes, int create, int flags, IntPtr template);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern int CloseHandle(IntPtr handle);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern int DeviceIoControl(IntPtr handle, DiskIoctl ioctl, byte[] inBuffer, int inBufferSize, byte[] outBuffer, int outBufferSize, ref int bytesReturned, IntPtr overlapped);

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetLogicalDriveStringsW", SetLastError = true)]
public static extern int GetLogicalDriveStrings(int bufferLength, byte[] buffer);

public enum DiskIoctl
{
    ScsiPassThrough = 315396,

    Lock = 589848,

    Unlock = 589852,

    Dismount = 589856,

    UpdateProperties = 459072,

    GetDiskLayout = 475148,

    SetDiskLayout = 507920
}

public enum ScsiOp
{
    ReadCapacity = 0x25,

    Read = 0x28,

    Write = 0x2A
}

这是可能的。我这样做是为了一个内部应用,所以我不能只是粘贴它的源代码,但我可以给你一些提示。你将不得不调用一些东西

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "CreateFileW", SetLastError = true)]
public static extern IntPtr CreateFile(string name, int access, int share, byte[] attributes, int create, int flags, IntPtr template);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern int CloseHandle(IntPtr handle);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern int DeviceIoControl(IntPtr handle, DiskIoctl ioctl, byte[] inBuffer, int inBufferSize, byte[] outBuffer, int outBufferSize, ref int bytesReturned, IntPtr overlapped);

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetLogicalDriveStringsW", SetLastError = true)]
public static extern int GetLogicalDriveStrings(int bufferLength, byte[] buffer);

public enum DiskIoctl
{
    ScsiPassThrough = 315396,

    Lock = 589848,

    Unlock = 589852,

    Dismount = 589856,

    UpdateProperties = 459072,

    GetDiskLayout = 475148,

    SetDiskLayout = 507920
}

public enum ScsiOp
{
    ReadCapacity = 0x25,

    Read = 0x28,

    Write = 0x2A
}

什么操作系统?我问这个问题只是因为我想知道我是在处理Windows API和CMD工具还是Linux API和shell工具。哦,对不起。是的,我在窗户上。在Visual Studio.net 2008中工作复制图像后,您打算对其执行什么操作?什么操作系统?我问这个问题只是因为我想知道我是在处理Windows API和CMD工具还是Linux API和shell工具。哦,对不起。是的,我在窗户上。在Visual Studio.net 2008中工作复制图像后,您打算对图像做什么?这不会给他图像。根据他的描述,他想要闪存驱动器的完整“扇区副本”。@Robaticus会丢失什么?@Robaticus-为什么会丢失?我是说把驱动器作为文件打开。Windows会允许你的。我不知道这对扇区复制有效。也许如果你有一些代码可以为他工作,那就不会给他形象。根据他的描述,他想要闪存驱动器的完整“扇区副本”。@Robaticus会丢失什么?@Robaticus-为什么会丢失?我是说把驱动器作为文件打开。Windows会允许你的。我不知道这对扇区复制有效。也许如果你有适合他的密码。