初始化和分区磁盘-如何防止“您需要格式化磁盘"消息出现了吗? [英] Initialize and partition disk - how to prevent "you need to format disk" message from appearing?

查看:214
本文介绍了初始化和分区磁盘-如何防止“您需要格式化磁盘"消息出现了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从应用程序初始化,分区和格式化磁盘.操作系统是Windows Server 2008 R2.在这些任务中使用哪种方法并不重要,但让我们假设我正在使用DeviceIoControl API.

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.

应用程序初始化并创建分区后,Windows会弹出一个消息框,提示您您需要格式化磁盘...

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.

有没有办法防止Windows弹出该消息框?

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

推荐答案

看上去情况比起我来要复杂一些.让我在这里解释我的发现,也许对其他人有用.

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.

以哪种方式初始化和格式化驱动器确实很重要.例如,以下 diskpart 脚本将执行所有操作,而Windows 将不会弹出该消息:

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.

但是在我的情况下,我不想依赖diskpart.我使用 DeviceIoControl API初始化磁盘并对其进行分区,然后等待WMI识别该卷,因此可以通过WMI对其进行格式化.

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.

不幸的是,锁定装置也不是一种选择.因为如果这样做,WMI将无法识别该音量.

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

基于此答案如何在不使用Windows分配驱动器号的情况下创建分区?我决定停止并启动 ShellHWDetection 服务,它实际上运行良好.

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.

这篇关于初始化和分区磁盘-如何防止“您需要格式化磁盘"消息出现了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆