1

With Windows SDK 7, we can use Virtual Disk API to create VHD image files but how can we format this image files (e.g FAT32 format), assign drive letter and copy some files into it? I could'n see any formatting function in the API?

ctasdemir
  • 383
  • 4
  • 13

2 Answers2

0

You will need to mount the disk, partition it and format it. You should be able to do this through the windows WMI interface,

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394572(v=VS.85).aspx

Angelom
  • 2,413
  • 1
  • 15
  • 8
0

Attach it via the AttachVirtualDisk function, then I assume you can just format it as a normal drive.

You could either use WMI (Format method of the Win32_Volume Class) or the SHFormatDrive function to format it.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
  • @ctas: This [article](http://msdn.microsoft.com/en-us/magazine/dd569754.aspx) explains the attaching etc and have some sample code. [Here](http://msdn.microsoft.com/en-us/library/windows/desktop/aa394558(v=vs.85).aspx) you can find some C++ sample code using WMI. – Hans Olsson Oct 25 '11 at 10:34
  • Thanks @ho1. Format functions normally expects volume name(C:, D: etc). When image files attached they seem like a physical disk but has no volume and partition. – ctasdemir Oct 25 '11 at 13:49
  • @ctas: Does `OpenVirtualDisk` work better? Otherwise, it's not a very solution, but you might be able to do it by automating the `diskpart` command line app? – Hans Olsson Oct 25 '11 at 14:04
  • Yes, OpenVirtualDisk opens and attaches Virtual Disk. I can do it by Diskpart's scripting support but i don't want. I think not all the functionality of API exposed. Dispart must be using the same API functions. If i can't find another way i will use Diskpart. – ctasdemir Oct 25 '11 at 14:14
  • @ctas: You could take a look at `DeviceIoControl` and [IOCTL_DISK_CREATE_DISK](http://msdn.microsoft.com/en-us/library/aa365155(VS.85).aspx) or maybe [IOCTL_DISK_SET_DRIVE_LAYOUT ](http://msdn.microsoft.com/en-us/library/aa365188(VS.85).aspx). Never used them so can't say for sure if you can format with them but it sounds like a possibility at least. – Hans Olsson Oct 25 '11 at 19:54