Initialize and partition disk - how to prevent “you need to format disk” message from appearing?

我们两清 提交于 2019-12-08 07:43:03

问题


I'm trying to initialize, partition and format a disk from application. OS is Windows Server 2008 R2. It doesn't really matter which method do I use for these tasks, but let's assume I'm using DeviceIoControl API.

As soon as application initializes and creates a partition Windows would pop a message box saying "You need to format disk...

"

So, even though my application immediately formats this disk, message box would still be there, and user would be confused, and can actually format it again.

Is there way to prevent Windows from popping that message box?


回答1:


As it appeared situation was a bit more complicated then I though originally. Let me explain my finding here, may be it will be useful for somebody else.

It really does matter which way you're initializing and formatting drive. For example the following diskpart script will do everything and Windows WILL NOT pop that message up:

select disk 2
create partition primary
select part 1
format fs=ntfs label="NEW DISK" quick
assign letter Z
exit

If you however try to assign letter first, and then perform format - message will appear.

But in my case I didn't want to have dependency on diskpart. 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.

And unfortunately locking device wasn't an option too. Because if I do that, WMI won't recognize the volume.

Based 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.



来源:https://stackoverflow.com/questions/15211900/initialize-and-partition-disk-how-to-prevent-you-need-to-format-disk-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!