
[已解決]如何在批處理中使用diskpart命令,刪除特定卷標(biāo)的分區(qū)最后由 5i365 于 -8-8 17:14本人平時(shí)刪除分區(qū)時(shí), 很少使用其它的第三方軟件, 都是在PE的磁盤(pán)管理下, 使用右鍵刪除分區(qū),但最近, 非常想嘗試一下使用批處理代碼來(lái)自動(dòng)刪除分區(qū), 看看效果如何,如果能實(shí)現(xiàn), 以后刪分區(qū)的操作相對(duì)而言就更簡(jiǎn)單了,改成特定卷標(biāo)就行了,例如,將要?jiǎng)h除分區(qū)的卷標(biāo)改為no,批處理執(zhí)行后相關(guān)的分區(qū)就刪除了因?yàn)橐赑E下使用, 而PE下不能執(zhí)行wmic命令, 所以只能使用diskpart命令, 具體描述如下:---先判斷WIN分區(qū)在哪個(gè)硬盤(pán),得到硬盤(pán)號(hào)!因?yàn)槭窃赑E下,Win系統(tǒng)的盤(pán)符有可能不為C,所以不能通過(guò)盤(pán)符做判斷, 可以根據(jù)分區(qū)下是否有windowssystem32文件夾判斷 【只處理包含window系統(tǒng)的硬盤(pán), 其它的硬盤(pán)即使有卷標(biāo)為no的分區(qū), 也不做處理 】---刪除卷標(biāo)為no的分區(qū),可能有一個(gè)或多個(gè), 而卷標(biāo)不為no的分區(qū)則保留 【根據(jù)卷標(biāo)得出盤(pán)符,然后sel volume=盤(pán)符如C 沒(méi)有冒號(hào):最后del volume noerr】---如果該硬盤(pán)中有ESP系統(tǒng)引導(dǎo)分區(qū), 即使卷標(biāo)不是no, 也刪除它 【最下面輸出信息中 type 為 system 的分區(qū) 是esp分區(qū)】---如果該硬盤(pán)中有MSR保留分區(qū), 即使卷標(biāo)不是no, 也刪除它 【最下面輸出信息中 type 為 Reserved 的分區(qū) 是MSR保留分區(qū)】---如果該硬盤(pán)中有恢復(fù)分區(qū), 即使卷標(biāo)不是no, 也刪除它, 【最下面輸出信息中 type 為 Recovery 的分區(qū) 是恢復(fù)分區(qū)】如果沒(méi)找到卷標(biāo)為no的分區(qū), 則彈出下面消息框, 點(diǎn)確定后, 腳本直接退出start mshta vbscript:msgbox(No partition no was found,0,tip)(window.close)&&exit上面幾種情況的判斷, 應(yīng)該要根據(jù)分區(qū)的類型來(lái)添加限定條件, 相關(guān)代碼參考鏈接:http://www.bathome.net/redirect. ... 9390&pid=242338感謝幾位大俠所推薦的無(wú)憂論壇的專門(mén)針對(duì)diskpart而寫(xiě)的腳本工具,雖然也可以實(shí)現(xiàn)效果,但是操作步驟感覺(jué)不太簡(jiǎn)單明了, 代碼量也非常多, 想自行修改下, 但能力有限, 實(shí)在吃不消另外,還有不少磁盤(pán)軟件, 如diskgnius, 傲梅助手等, 都可以實(shí)現(xiàn)我要的效果, 但是不在此貼的討論范圍, 感覺(jué)還是系統(tǒng)內(nèi)置的工具來(lái)的直接期待諸位高手, 盡量能用最少的代碼, 實(shí)現(xiàn)上面功能, 那將非常震撼, 提前感謝!下面是完整的手動(dòng)刪除分區(qū)操作步驟:提醒:為了讓代碼中英文系統(tǒng)兼容性更好,最好在批處理代碼最前面加上chcp 437切換到英文,這樣會(huì)輸出英文信息,就像最下面的輸出信息那樣________________________________________________________________________________Microsoft Windows [Version 6.1.7601]Copyright (c) 2009 Microsoft Corporation.All rights reserved.C:UsersAdministrator>chcp 437Active code page: 437X:UsersAdministrator>diskpartMicrosoft DiskPart version 10.0.19041.1Copyright (C) Microsoft Corporation.On computer: WinpeDISKPART> sel disk 1Disk 1 is now the selected disk.DISKPART> detail diskTOSHIBA MK1655GSX USB DeviceDisk ID: {AA01743D-F6E3-11EB-8FB7-08107649E626}Type : USBStatus : onlinePath : 0Target : 0LUN ID : 0Location Path : UNAVAILABLECurrent Read-only State : NoRead-only: NoBoot Disk: NoPagefile Disk: NoHibernation File Disk: NoCrashdump Disk: NoClustered Disk: NoVolume ###LtrLabelFs TypeSize Status Info---------------------------------------------------------------Volume 3 F nonTFS Partition 39 GBHealthyVolume 4 G soft NTFS Partition 20 GBHealthyVolume 5 H data NTFS Partition 60 GBHealthyVolume 6 IRAWPartition 10 GBHealthyVolume 7NTFS Partition 19 GBHealthyHiddenVolume 8FAT32Partition300 MBHealthyHiddenDISKPART> list partPartition ###TypeSize Offset-------------------------------------------Partition 1System 300 MB1024 KBPartition 2Reserved16 MB 301 MBPartition 3Primary 39 GB 317 MBPartition 4Primary 20 GB39 GBPartition 5Primary 60 GB59 GBPartition 6Recovery10 GB 119 GBPartition 7Primary 19 GB 129 GBDISKPART> sel part 1Partition 1 is now the selected partition.DISKPART> del part overrideDiskPart successfully deleted the selected partition.DISKPART> sel part 2Partition 2 is now the selected partition.DISKPART> del part overrideDiskPart successfully deleted the selected partition.DISKPART> sel part 3Partition 3 is now the selected partition.DISKPART> del part overrideDiskPart successfully deleted the selected partition.DISKPART> sel part 6Partition 6 is now the selected partition.DISKPART> del part overrideDiskPart successfully deleted the selected partition.

