Tuesday, October 6, 2015

ImDisk Simple USB Drive

ImDisk is a dll which contains methods to emulate various storage devices (HDD, USB, CD).
unfortunately I haven't seen any seen any examples that i can use.
although there is a very detailed documents on the methods
http://www.ltr-data.se/library/ImDiskNet/html/b33f1e89-3d92-fc08-248d-14c5c2efd549.htm

so here is a simple example how to create a USB drive and disconnect it
// get device handle and free drive letter
uint deviceID = 0;
IntPtr statusControl = IntPtr.Zero;

string driveLetter = ImDiskAPI.FindFreeDriveLetter() + ":";

// create device          
// 40mb = 4096*1024*10
ImDiskAPI.CreateDevice(4096 * 1024 * 10, 0, 0, 0, 0, ImDiskFlags.Removable , @"USB", false, driveLetter, ref deviceID, statusControl);

Console.ReadKey();

// remove device        
ImDiskAPI.APIFlags = DLL.ImDiskAPIFlags.ForceDismount;
ImDiskAPI.RemoveDevice(driveLetter);

No comments:

Post a Comment