Because if I do that, WMI won't recognize the volume.īased on this answer How to create a partition without Windows assigning a drive letter? I decided to go with stopping and starting ShellHWDetection service and it actually worked out perfectly. I used DeviceIoControl API to initialize and partition disk and then was waiting for WMI to recognize the volume, so I can format it via WMI.Īnd unfortunately locking device wasn't an option too. If you however try to assign letter first, and then perform format - message will appear.īut in my case I didn't want to have dependency on diskpart. For example the following diskpart script will do everything and Windows WILL NOT pop that message up: select disk 2 It really does matter which way you're initializing and formatting drive. When you done Initialization, in the disk map, the disk shows as unallocated space, right click on the Disk you want to convert, choose Convert to GPT disk (click on the beginning of the disk or the middle or. Step 1: use short cut key: WIN+R to open run box, Type diskpart. Initialize a disk from command line diskpart is fast and easy, the following commands with help. You can start a line with rem to make the line a comment. Let me explain my finding here, may be it will be useful for somebody else. You can directly type disk management in Windows 10 start menu, then Enter to run Disk Management. Initializing Windows Disks with DiskPart. To create a diskpart script, create a text file that contains the Diskpart commands that you want to run, with one command per line, and no empty lines. As it appeared situation was a bit more complicated then I though originally.