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

[文件操作] 【已解决】如何判定当前系统所在分区是GPT分区还是MBR分区

本帖最后由 电动小马达 于 2020-1-30 16:11 编辑

我的思路大概是这样,不过限于水平有限,不能写成bat文件,希望大佬们帮帮忙
1.判定%systemdrive%分区盘符,这个可以通过%systemdrive%直接获得,例如C。
2.通过diskpart命令-list vol获得C盘所在的卷标,并选定
  1. DISKPART> list vol
  2.   卷 ###      LTR  标签         FS     类型        大小     状态       信息
  3.   ----------  ---  -----------  -----  ----------  -------  ---------  --------
  4.   卷     0         Files        NTFS   磁盘分区         200 MB  正常
  5.   卷     1     E   Work_M       NTFS   磁盘分区          30 GB  正常
  6.   卷     2     D   Files_M      NTFS   磁盘分区         168 GB  正常         页面文件
  7.   卷     3     H   Win7         NTFS   磁盘分区          39 GB  正常
  8.   卷     4     C   Windows_OS   NTFS   磁盘分区          85 GB  正常         启动
  9.   卷     5     F   VHD & Syste  NTFS   磁盘分区         110 GB  正常
  10.   卷     6     G   新加卷          NTFS   磁盘分区          39 GB  正常
  11.   卷     7         Win7         FAT32  磁盘分区         369 MB  正常
  12.   卷     8         PE           FAT32  磁盘分区        2510 MB  正常
  13.   卷     9         Win10        FAT32  磁盘分区         300 MB  正常         系统
  14. DISKPART> sel vol 4
  15. 卷 4 是所选卷。
复制代码
3.通过UNIQUEID DISK命令是GPT分区还是MBR分区,
  1. DISKPART>  UNIQUEID DISK
  2. 磁盘 ID: {EB821A68-5E27-43D8-B993-C5167ECA28F2}
复制代码
GPT分区会显示类似于以下内容
  1. 磁盘 ID: {EB821A68-5E27-43D8-B993-C5167ECA28F2}
复制代码
MBR分区会显示类似于以下内容
  1. 磁盘 ID: B04C1898
复制代码
4.如果是GPT分区则echo GPT,如果是MBR分区则echo MBR并运行%systemdrive%\oem\1.exe

本帖最后由 went 于 2020-1-26 23:20 编辑
  1. @echo off
  2. powershell -c "(Get-Disk -Partition (Get-Partition -DriveLetter $env:SystemDrive.Substring(0,1))).PartitionStyle"
  3. pause
复制代码
电脑上要有powershell,保存为bat文件运行

TOP

回复 2# went

win10下没问题,但是需要执行的电脑是win7,执行后显示为
  1. 无法将“Get-Disk”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称
  2. 的拼写,如果包括路径,请确保路径正确,然后重试。
  3. 所在位置 行:1 字符: 10
  4. + (Get-Disk <<<<  -Partition (Get-Partition -DriveLetter $env:SystemDrive.Subst
  5. ring(0,1))).PartitionStyle
  6.     + CategoryInfo          : ObjectNotFound: (Get-Disk:String) [], CommandNot
  7.    FoundException
  8.     + FullyQualifiedErrorId : CommandNotFoundException
  9. 请按任意键继续. . .
复制代码

TOP

  1. wmic path win32_logicaldisk where "deviceid='c:'" assoc:list /resultclass:win32_diskpartition|find /i "Type=GPT"&&echo GPT||echo MBR
复制代码
微信:flashercs
QQ:49908356

TOP

  1. @Echo Off&Color 0e
  2. cd/d %~dp0
  3. call:Diskpart_List_Disk
  4. pause
  5. goto:eof
  6. :Diskpart_List_Disk
  7. Reg.exe Query "HKU\S-1-5-19" >nul 2>nul||exit
  8. if not %ErrorLevel% equ 0 exit
  9. set "#Grant_Administrators_F$=%SystemRoot%\System32\zh-CN\Diskpart.exe.mui"
  10. If Exist "%#Grant_Administrators_F$%" >nul 2>nul Takeown.exe /f "%#Grant_Administrators_F$%"
  11. If Exist "%#Grant_Administrators_F$%" >nul 2>nul Icacls.exe "%#Grant_Administrators_F$%" /Grant Administrators:f")
  12. If Exist "%#Grant_Administrators_F$%" >nul 2>nul ren "%#Grant_Administrators_F$%" "Diskpart.exe.mui.bak"
  13. >nul 2>nul set #Diskpart_Volume$
  14. if %ErrorLevel% Geq 2 for /f "delims==" %%i in ('"set #Diskpart_Volume$"')do set "%%i="
  15. for /f "skip=8 eol=D tokens=* delims=" %%i in ('"(echo,List Disk)|Diskpart.exe"')do for /f "tokens=1,2,3,4,5,6,7,8 delims=  " %%s in ("%%i")do for /f "skip=27 eol=D tokens=1,2,3,* delims=  " %%i in ('"(echo,select disk %%t&echo,DetAil disk)|Diskpart.exe"')do if /i "%%t%%z"=="%%t" (set "#Diskpart_Volume_%%k$=%%k;%%t;MBR")else (set "#Diskpart_Volume_%%k$=%%k;%%t;GPT")
  16. for /f "skip=8 eol=D tokens=* delims=" %%i in ('"(echo,List Disk)|Diskpart.exe"')do for /f "tokens=1,2,3,4,5,6,7,8 delims=  " %%s in ("%%i")do for /f "skip=8 eol=D tokens=* delims=" %%i in ('"(echo,select disk %%t&echo,DetAil disk)|Diskpart.exe"')do if not defined #Diskpart_Disk_%%t$ set "#Diskpart_Disk_%%t$=%%t;%%i"
  17. set "#Diskpart_Volume_
  18. set "#Diskpart_Disk_
  19. If Exist "%#Grant_Administrators_F$%.bak" >nul 2>nul ren "%SystemRoot%\System32\zh-CN\Diskpart.exe.mui.bak" "Diskpart.exe.mui"
  20. set "#Error_Diskpart_Volume$="&&set "#Error_Diskpart_Disk$="
  21. >nul 2>nul set #Diskpart_Volume_
  22. if %ErrorLevel% equ 0 set "#Error_Diskpart_Volume$=1"
  23. >nul 2>nul set #Diskpart_Disk_
  24. if %ErrorLevel% equ 0 set "#Error_Diskpart_Disk$=1"
  25. goto:eof
复制代码
这么好的论坛你上哪找,运行测试环境为6.1.7601-64
注:请遵守互联网信息安全,勿用于非法用途

TOP

返回列表