private static bool PreventVolumeRemoval(IntPtr handle, bool prevent) { byte[] buf = new byte[1]; uint retVal; buf[0] = prevent ? (byte)1 : (byte)0; return(OSDelegate.DeviceIoControl(handle, IOCTL_STORAGE_MEDIA_REMOVAL, buf, 1, IntPtr.Zero, 0, out retVal, IntPtr.Zero)); }
private static bool DismountVolume(IntPtr handle) { uint byteReturned; return(OSDelegate.DeviceIoControl(handle, FSCTL_DISMOUNT_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, out byteReturned, IntPtr.Zero)); }
private static bool LockVolume(IntPtr handle) { uint byteReturned; return(OSDelegate.DeviceIoControl(handle, FSCTL_LOCK_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, out byteReturned, IntPtr.Zero)); }
private static IntPtr DriveFileHandle(string driveLetter) { string filename = string.Format(@"\\.\{0}", driveLetter); return(OSDelegate.CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, 0x3, 0, IntPtr.Zero)); }
private static bool CloseHandle(IntPtr handle) { return(OSDelegate.CloseHandle(handle)); }
private static bool EjectVolume(IntPtr handle) { uint byteReturned; return(OSDelegate.DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, out byteReturned, IntPtr.Zero)); }