[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 求助批处理diskpart 实在写不下去了

本帖最后由 dong3626 于 2023-4-17 10:40 编辑

具体需求在下面代码中
  1. @echo off
  2. ::自动请求以管理员权限运行
  3. if /i "%systemdrive%"=="C:" reg query HKU\S-1-5-20>nul 2>nul || echo;CreateObject^("Shell.Application"^).ShellExecute "%~f0", "%*", "", "runas", 1 > "%temp%\getadmin.vbs" && cscript //b "%temp%\getadmin.vbs" && exit /b & del "%temp%\getadmin.vbs" /f /q>nul
  4. SetLocal EnableDelayedExpansion
  5. ::设置批处理所在目录
  6. set DIR_CUR=%~dp0
  7. cd %DIR_CUR%
  8. ECHO.
  9. ECHO 当前挂载硬盘:
  10. ECHO ---------------------------------------------------------
  11. echo.
  12. echo 序号 格式  协议   容量   型号            <--- 硬盘大小可不要
  13. echo ---  ---   ----  ------  --------
  14. ECHO  0   GPT   NVME   256GB  WD256
  15. ECHO  1   MBR   SATA  1000GB  WD1000
  16. ECHO.
  17. echo 序号 盘:区   大小    盘符   FS  EFI/MSR   系统    标签            <--- 标签可不要
  18. echo ---  -----  ------   ---  ----- -------  ------   ------
  19. echo  1    0:1    500MB    Z   FAT32   EFI             EFI
  20. echo  2    0:2    128MB                MSR               
  21. echo  3    0:3    100GB    C    NTFS           WIN10   WIN      
  22. echo  4    0:4    100GB                                Mac
  23. echo  5    0:5     37GB    D   exFat                   SHARE
  24. echo  6    1:1    500GB    E    NTFS
  25. echo  7    1:2    456GB    F    NTFS
  26. ECHO ---------------------------------------------------------
  27. echo 可根据磁盘分区编号选择,返回分区的详细信息
  28. echo.
  29. :: 保存磁盘信息
  30. :: set DISK_N
  31. :: 保存分区信息
  32. :: set PART_N
  33. for /f "skip=9 tokens=2 delims= " %%a in ('echo list disk^|diskpart') do (
  34.    rem 下面提取硬盘信息
  35.    for /f "delims=" %%b in ('(echo sel disk %%a ^& echo detail disk^)^|diskpart') do (
  36.       rem 取三行,硬盘型号,id->硬盘分区格式,磁盘类型
  37.       set "cl=%%b"
  38.       set /a l+=1
  39.       if "!cl:~0,5!"=="在计算机上" (set /a t=!l!+4 & set /a i=!l!+5 & set /a p=!l!+6)
  40.       if !l!==!t! (set tt=!cl!)
  41.       if !l!==!i! (set did=!cl:~7! & (if "!did:-=!"=="!did!" (set "ii=MBR") else (set "ii=GPT")))
  42.       if !l!==!p! (set pp=!cl:~7! & (echo. & echo --- 硬盘:%%a !pp!  !ii! !tt! ---) & set "DISK_%%a= %%a !pp! !ii! !tt!")
  43.    )
  44.    rem 下面遍历每个分区,并提取合并处理每个分区的信息
  45.    for /f "tokens=2 delims= " %%c in ('(echo sel disk %%a ^& echo list part ^& exit^)^|diskpart^|findstr /i "系统 主要 未知 保留 逻辑"') do (
  46.       set /a PARTT+=1
  47. ::      echo 当前分区 %%a:%%c
  48.       for /f "delims=" %%d in ('(echo sel disk %%a ^& echo list part ^& echo sel part %%c ^& echo det part^)^|diskpart') do (
  49. ::         echo %%a:%%c 分区信息 %%d
  50.          set "cll=%%d"
  51.          set /a ll+=1
  52.          if "!cll:~0,7!"=="  分区   " (
  53.             for /f "tokens=2-5 delims= " %%e in ("!cll!") do (
  54.                if %%c==%%e (set tinfo=%%a:%%c   %%f   %%g%%h)
  55.             )
  56.          )
  57. ::         if "!cll:~0,2!"=="类型" (echo !cll:~6! 提取对照生成准确文件系统)
  58.          if "!cll:~0,4!"=="字节偏移" (set /a lll=!ll!+3 & set /a kkk=!ll!+2)
  59.          if !ll!==!lll! (if "!cll:~0,1!"=="*" (echo  !PARTT!  !tinfo! !cll:~13,23!))
  60.          if !ll!==!kkk! (if "!cll:~0,1!"=="D" (echo  !PARTT!  !tinfo!))
  61.       )
  62.    )
  63. )
  64. echo.
  65. pause>nul
复制代码

回复 1# dong3626


    具体需求在第几行?
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复  dong3626


    具体需求在第几行?
Batcher 发表于 2023-4-16 17:13



49行往后,每个分区 list part 和 det part 生成的信息合并

感谢

TOP

本帖最后由 dong3626 于 2023-4-16 20:28 编辑

用于 对照生成文件系统的信息,省略了一小部分。
抄自 dpinfo
  1. (rem 设置分区ID,用于文件系统辅助识别
  2. set "$01=FAT12"
  3. set "$02=Xenix /"
  4. set "$03=Xenix /usr"
  5. set "$04=FAT16 <32M"
  6. set "$05=Extended"
  7. set "$06=FAT16 >=32M"
  8. set "$07=HPFS/NTFS/exFAT"
  9. set "$08=AIX"
  10. set "$09=AIX Boot"
  11. set "$0A=OS/2 Boot"
  12. set "$0B=FAT32"
  13. set "$0C=FAT32 LBA"
  14. set "$0E=FAT16 LBA"
  15. set "$0F=Extended LBA"
  16. set "$10=OPUS"
  17. set "$11=Hidden FAT12"
  18. set "$12=Compaq Diagnostics"
  19. set "$14=Hidden FAT16 <32M"
  20. set "$16=Hidden FAT16 >=32M"
  21. set "$17=Hidden HPFS/NTFS"
  22. set "$18=AST Swap"
  23. set "$1B=Hidden FAT32"
  24. set "$1C=Hidden FAT32 LBA"
  25. set "$1E=Hidden FAT16 LBA"
  26. set "$24=NEC DOS"
  27. set "$27=Microsoft Recovery Partition"
  28. set "$35=OS/2 JFS"
  29. set "$38=THE OS V3 2gb"
  30. set "$39=THE OS V4 spanned"
  31. set "$3A=THE OS V4 4gb"
  32. set "$3B=THE OS V4 extended"
  33. set "$3C=PartitionMagic recovery"
  34. set "$3D=Novell Netware(Hidden)"
  35. set "$40=VENIX 286"
  36. set "$41=Linux/MINIX (sharing with DRDOS)"
  37. set "$42=RAID"
  38. set "$43=Linux native (sharing with DRDOS)"
  39. set "$45=Boot-US"
  40. set "$4C=Oberon"
  41. set "$4D=QNX 4.2 Primay"
  42. set "$4E=QNX 4.2 Secondary"
  43. set "$4F=QNX 4.2 Tertiary"
  44. set "$50=DM (DIsk Danager)"
  45. set "$51=Novell(or DM6 Aux1)"
  46. set "$52=CP/M or Microport SysV/AT"
  47. set "$53=DM6 Aux3"
  48. set "$54=DM6"
  49. set "$55=ES-Drive (Disk Manager)"
  50. set "$56=Golded Bow (Disk Manager)"
  51. set "$57=DrivePro"
  52. set "$5C=Priam Edisk (Disk Manager)"
  53. set "$61=SpeedStor"
  54. set "$63=UNIX, System V/386, GNU HURD or Mach"
  55. set "$64=Novell Netware/286 2.xx"
  56. set "$65=Novell Netware/386 3.xx"
  57. set "$66=Novell"
  58. set "$67=Novell"
  59. set "$68=Novell"
  60. set "$69=Novell"
  61. set "$70=DiskSecure Multi-Boot"
  62. set "$74=Scramdisk"
  63. set "$75=PC/IX"
  64. set "$77=QNX4.x"
  65. set "$78=QNX4.x 2nd part"
  66. set "$79=QNX4.x 3rd part"
  67. set "$80=Minix util 1.4a"
  68. set "$81=Early Linux, or Minix since 1.4b"
  69. set "$82=Linux Swap"
  70. set "$83=Linux Native, or Ext2/3/4 (Linux Data)"
  71. set "$85=Linux extended"
  72. set "$86=FAT16 volume"
  73. set "$87=NTFS volume"
  74. set "$8B=FAT32 volume"
  75. set "$8C=FAT32 LBA volume"
  76. set "$93=Amoeba"
  77. set "$94=Amoeba bad block table"
  78. set "$9F=BSD/OS"
  79. set "$A0=Hibernation"
  80. set "$A1=Hibernation"
  81. set "$A5=FreeBSD/NetBSD"
  82. set "$A6=OpenBSD"
  83. set "$A7=NextStep"
  84. set "$A9=NetBSD"
  85. set "$AA=Olivetti FAT12"
  86. set "$AC=IBM JFS"
  87. set "$B7=BSDI BSD/386"
  88. set "$B8=BSDI BSD/386 Swap"
  89. set "$BE=Solaris boot"
  90. set "$C0=DR-DOS"
  91. set "$C1=DRDOS/sec FAT12"
  92. set "$C4=DRDOS/sec FAT16"
  93. set "$C6=Corrupted FAT16"
  94. set "$C7=Corrupted NTFS"
  95. set "$D8=CP/M-86"
  96. set "$DB=CP/M, Concurrent DOS or CTOS"
  97. set "$DF=BootIt"
  98. set "$E1=DOS access FAT12"
  99. set "$E3=DOS R/O or SpeedStor"
  100. set "$E4=SpeedStor FAT16"
  101. set "$EB=BeOS"
  102. set "$EE=Protected MBR"
  103. set "$EF=EFI System Partition"
  104. set "$F1=SpeedStor"
  105. set "$F2=DOS 3.3+ Secondary"
  106. set "$F4=SpeedStor Large"
  107. set "$FB=VMware VMFS"
  108. set "$FC=VMware Swap"
  109. set "$FD=Linux RAID"
  110. set "$FE=SpeedStor"
  111. set "$FF=XENIX bad blocks table"
  112. rem 设置GPT标识符,数据来自英文维基百科,不保证正确,仅供参考
  113. set "$00000000-0000-0000-0000-000000000000=未使用"
  114. set "$024DEE41-33E7-11D3-9D69-0008C781F39F=MBR分区表"
  115. set "$C12A7328-F81F-11D2-BA4B-00A0C93EC93B=ESP"
  116. set "$21686148-6449-6E6F-744E-656564454649=BIOS引导分区"
  117. set "$D3BFE2DE-3DAF-11DF-BA40-E3A556D89593=iFFS分区(Intel快速启动)"
  118. set "$F4019732-066E-4E12-8273-346C5641494F=Sony引导分区"
  119. set "$BFBFAFE7-A34F-448A-9A5B-6213EB736C22=Lenovo引导分区"
  120. set "$E3C9E316-0B5C-4DB8-817D-F92DF00215AE=MSR"
  121. set "$EBD0A0A2-B9E5-4433-87C0-68B6B72699C7=基本数据分区"
  122. set "$5808C8AA-7E8F-42E0-85D2-E1E90434CFB3=LDM元数据分区"
  123. set "$AF9B60A0-1431-4F62-BC68-3311714A69AD=LDM数据分区"
  124. set "$DE94BBA4-06D1-4D40-A16A-BFD50179D6AC=WinRE"
  125. set "$37AFFC90-EF7D-4E96-91C3-2D7AE055B174=IBM GPFS分区"
  126. set "$E75CAF8F-F680-4CEE-AFA3-B001E56EFC2D=存储空间分区"
  127. set "$75894C1E-3AEB-11D3-B7C1-7B03A0000000=HP-UX 数据分区"
  128. set "$E2A1E728-32E3-11D6-A682-7B03A0000000=HP-UX 服务分区"
  129. set "$0FC63DAF-8483-4772-8E79-3D69D8477DE4=Linux 文件系统数据"
  130. set "$A19D880F-05FC-4D3B-A006-743F0F84911E=Linux RAID 分区"
  131. set "$44479540-F297-41B2-9AF7-D131D5F0458A=Linux / (x86)"
  132. set "$4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709=Linux / (x86-64)"
  133. set "$69DAD710-2CE4-4E3C-B16C-21A1D49ABED3=Linux / (32-bit ARM)"
  134. set "$B921B045-1DF0-41C3-AF44-4C6F280D3FAE=Linux / (64-bit ARM/AArch64)"
  135. set "$0657FD6D-A4AB-43C4-84E5-0933C84B4F4F=Linux 交换分区"
  136. set "$E6D6D379-F507-44C2-A23C-238F2A3DF928=Linux 逻辑卷管理器(LVM)分区"
  137. set "$933AC7E1-2EB4-4F13-B844-0E14E2AEF915=Linux /home"
  138. set "$3B8F8425-20E0-4F3B-907F-1A25A76F98E8=Linux /srv"
  139. set "$7FFEC5C9-2D00-49B7-8941-3EA10A5586B7=Linux 普通dm-crypt分区"
  140. set "$CA7D7CCB-63ED-4C53-861C-1742536059CC=Linux LUKS分区"
  141. set "$8DA63339-0007-60C0-C436-083AC8230908=Linux 保留"
  142. set "$83BD6B9D-7F41-11DC-BE0B-001560B84F0F=FreeBSD 启动分区"
  143. set "$516E7CB4-6ECF-11D6-8FF8-00022D09712B=FreeBSD 数据分区"
  144. set "$516E7CB5-6ECF-11D6-8FF8-00022D09712B=FreeBSD 交换分区"
  145. set "$516E7CB6-6ECF-11D6-8FF8-00022D09712B=FreeBSD UFS分区"
  146. set "$516E7CB8-6ECF-11D6-8FF8-00022D09712B=FreeBSD Vinum 卷管理器分区"
  147. set "$516E7CBA-6ECF-11D6-8FF8-00022D09712B=FreeBSD ZFS分区"
  148. set "$48465300-0000-11AA-AA11-00306543ECAC=Mac OS X HFS+分区"
  149. set "$7C3457EF-0000-11AA-AA11-00306543ECAC=Mac OS X Apple APFS"
  150. set "$55465300-0000-11AA-AA11-00306543ECAC=Mac OS X Apple UFS container"
  151. set "$6A898CC3-1DD2-11B2-99A6-080020736631=Mac OS X ZFS"
  152. set "$52414944-0000-11AA-AA11-00306543ECAC=Mac OS X Apple RAID分区"
  153. set "$52414944-5F4F-11AA-AA11-00306543ECAC=Mac OS X Apple RAID分区,离线"
  154. set "$426F6F74-0000-11AA-AA11-00306543ECAC=Mac OS X Apple引导分区(恢复HD)"
  155. set "$4C616265-6C00-11AA-AA11-00306543ECAC=Mac OS X Apple Label"
  156. set "$5265636F-7665-11AA-AA11-00306543ECAC=Mac OS X Apple TV恢复分区"
  157. set "$53746F72-6167-11AA-AA11-00306543ECAC=Mac OS X Apple 核心存储分区 "
  158. set "$B6FA30DA-92D2-4A9A-96F1-871EC6486200=Mac OS X SoftRAID_Status"
  159. set "$2E313465-19B9-463F-8126-8A7993773801=Mac OS X SoftRAID_Scratch"
  160. set "$FA709C7E-65B1-4593-BFD5-E71D61DE9B02=Mac OS X SoftRAID_Volume"
  161. set "$BBBA6DF5-F46F-4A89-8F59-8765B2727503=Mac OS X SoftRAID_Cache"
  162. set "$6A82CB45-1DD2-11B2-99A6-080020736631=Solaris illumos启动分区"
  163. set "$6A85CF4D-1DD2-11B2-99A6-080020736631=Solaris /"
  164. set "$6A87C46F-1DD2-11B2-99A6-080020736631=Solaris 交换分区"
  165. set "$6A8B642B-1DD2-11B2-99A6-080020736631=Solaris 备份分区"
  166. set "$6A898CC3-1DD2-11B2-99A6-080020736631=Solaris /usr"
  167. set "$6A8EF2E9-1DD2-11B2-99A6-080020736631=Solaris /var"
  168. set "$6A90BA39-1DD2-11B2-99A6-080020736631=Solaris /home"
  169. set "$6A9283A5-1DD2-11B2-99A6-080020736631=Solaris 备用扇区"
  170. set "$6A945A3B-1DD2-11B2-99A6-080020736631=Solaris 保留分区"
  171. set "$6A9630D1-1DD2-11B2-99A6-080020736631=Solaris 保留分区"
  172. set "$6A980767-1DD2-11B2-99A6-080020736631=Solaris 保留分区"
  173. set "$6A96237F-1DD2-11B2-99A6-080020736631=Solaris 保留分区"
  174. set "$6A8D2AC7-1DD2-11B2-99A6-080020736631=Solaris 保留分区"
  175. set "$49F48D32-B10E-11DC-B99B-0019D1879648=NetBSD 交换分区"
  176. set "$49F48D5A-B10E-11DC-B99B-0019D1879648=NetBSD FFS分区"
  177. set "$49F48D82-B10E-11DC-B99B-0019D1879648=NetBSD LFS分区"
  178. set "$49F48DAA-B10E-11DC-B99B-0019D1879648=NetBSD RAID分区"
  179. set "$2DB519C4-B10F-11DC-B99B-0019D1879648=NetBSD 串联分区"
  180. set "$2DB519EC-B10F-11DC-B99B-0019D1879648=NetBSD 加密分区"
  181. set "$FE3A2A5D-4F32-41A7-B725-ACCC3285A309=Chrome OS 内核"
  182. set "$3CB8E202-3B7E-47DD-8A3C-7FF2A13CFCEC=Chrome OS 根文件系统"
  183. set "$2E0A753D-9E48-43B0-8337-B15192CB1B5E=Chrome OS 未来用途"
  184. set "$42465331-3BA3-10F1-802A-4861696B7521=Haiku BFS"
  185. set "$85D5E45E-237C-11E1-B4B3-E89A8F7FC3A7=MidnightBSD 启动分区"
  186. set "$85D5E45A-237C-11E1-B4B3-E89A8F7FC3A7=MidnightBSD 数据分区"
  187. set "$85D5E45B-237C-11E1-B4B3-E89A8F7FC3A7=MidnightBSD 交换分区"
  188. set "$0394EF8B-237E-11E1-B4B3-E89A8F7FC3A7=MidnightBSD UFS分区"
  189. set "$85D5E45C-237C-11E1-B4B3-E89A8F7FC3A7=MidnightBSD Vinum 卷管理器分区"
  190. set "$85D5E45D-237C-11E1-B4B3-E89A8F7FC3A7=MidnightBSD ZFS分区"
  191. set "$824CC7A0-36A8-11E3-890A-952519AD3F61=OpenBSD 数据分区"
  192. set "$CEF5A9AD-73BC-4601-89F3-CDEEEEE321A1=QNX Power-safe (QNX6) 文件系统"
  193. set "$C91818F9-8025-47AF-89D2-F030D7000C2C=Plan 9 分区"
  194. set "$9D275380-40AD-11DB-BF97-000C2911D1B8=VMware ESX vmkcore (核心转储分区)"
  195. set "$AA31E02A-400F-11DB-9590-000C2911D1B8=VMware ESX VMFS文件系统分区"
  196. set "$9198EFFC-31C0-11DB-8F78-000C2911D1B8=VMware ESX VMware 保留"
复制代码

TOP

dpinfo 里面的代码,参考价值很大,但是代码量太大,实在消化不动

TOP

回复 1# dong3626


如果可以用powershell ,http://www.bathome.net/thread-65340-1-1.html

TOP

回复 5# dong3626


    哪里看不懂就找dpinfo的作者问问吧,作者不告诉你吗?
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

返回列表