通过批处理或 vbs 脚本删除驱动器号

Remove drive letters via batch or vbs scripting

我正在搜索执行以下操作的小批处理或 vbs 脚本:

非常感谢任何建议。

您可以使用命令行工具 "diskpart" 执行此操作。如 official technet documentation 中所述,如果您知道卷名,则可以使用以下命令将其删除:

select volume <volume number>
remove letter=<Letter>

您可以使用脚本文件(如 documented here) with the exact commands, or by calling the exe with objShell.Exec on the shell object in vbscript and manipulating the stdin and stdout accordingly. An example for that can be found here)自动执行此操作。在您的情况下,这可能是更好的方法,因为您可以在那里执行 "list volume",然后解析结果以进行描述并标记并相应地采取行动。遗憾的是,这是获得卷号的唯一方法,因为它不存在于 wmi 或更容易查询的地方。

请记住,diskpart 是一个非常强大的工具,可以擦除整个分区,因此请谨慎使用。

另请注意:

You cannot remove the drive letters on system, boot, or paging volumes. In addition, you cannot remove the drive letter for an OEM partition, any GPT partition with an unrecognized GUID, or any of the special, non-data, GPT partitions such as the EFI system partition.