|
本帖最后由 dos时代菜鸟 于 2021-1-14 15:59 编辑
liuzhaoyzz 发表于 2021-1-14 12:36
结果还是不对,从FAT32分区启动,本来有盘符是H,结果提示挂载到了Z盘,资源管理器里面看不到Z盘,回车继 ...
这个说明是成功的,脚本需要改进下。
1.你的系统缺少 bcdedit ,这个可能是系统的事情。
2.diskpart 找到 目标卷,没有把 对应的 盘符 赋值,这个需要 脚本改进
如下:
dpy.351.cmd.7z
(1.85 KB, 下载次数: 11)
- @echo off
- setlocal ENABLEDELAYEDEXPANSION
- rem 通过diskpart获取 bcd 启动硬盘和分区,为其分配/卸载盘符。
- rem 涉及命令 chcp diskpart bcdedit ,批处理指令 for if set exit echo call 等
- rem 脚本中 call:XXXX 有一个 errorlevel 返回值,由 exit /b N 设定,如果 errorlevel=1 就说明该程序段 没有达到目的,如果 返回0 ,说明成功了。
- call:init
- if errorlevel 1 goto :end0
- set x=Y
- if not "!bcd_ltr!"=="" (
- set /p x=Will dismount Volume !bcd_vol! from !bcd_ltr!: , Are you sure^(Yes/No^)?___
- if /i "!x: =!" == "N" goto end0
- if /i "!x: =!" == "Y" call:load_script script_down
- ) else (
- set /p x=Will mount Volume !bcd_vol! to !ltrs:~-1!: , Are you sure^(Yes/No^)?___
- if /i "!x: =!" == "N" goto end0
- if /i "!x: =!" == "Y" call:load_script script_up
- )
- :end0
- pause
- if exist %tempfile% del %tempfile%
- goto :eof
- rem 初始化---初始化定义一些变量 并获取 bcd_vol ----------------
- :init
- for %%c in ( chcp.com diskpart.exe bcdedit.exe) do (
- if not exist %windir%\system32\%%c (
- echo Components is not found : %%c !
- exit /b 1
- )
- )
-
- for /f "tokens=2 delims=:" %%c in ('chcp') do (set page=%%c)
- for %%c in (936 437) do (if !page! equ %%c set page_code=ok)
- if not defined page_code ( echo Page_code Error! && exit /b 1)
- set "CN_str1=卷"
- set "CN_str2=系统"
-
- SET "EN_str1=Volume"
- set "EN_str2=System"
- set "分割线=-------------------------------------------------------------------------------------------"
- set tempfile="%temp%\%~n0.diskpart_script_temp"
- set Used_LTRs=,
-
- echo !分割线!
- call:bcdedit
- if errorlevel 1 (
- set bcdedit_error=1
- echo BCDedit did not find BCD_VOL!
- )
- >%tempfile% echo list vol
- for /f "delims=" %%c in ('diskpart /s %tempfile%') do (
- set l0=%%c && set "l0= !l0:~1!"
- for /f "tokens=1,2" %%h in ("!l0!") do (
- CALL:STR_X str1 %%h
- if not errorlevel 1 (
- SET "ltr=!l0:~14,3!" && set "ltr=!ltr: =!" && set Used_LTRs=!used_ltrs!,!ltr!
- set vol_ltr_s=!vol_ltr_s!%%i:!ltr!,
- if defined bcd_vol (if /i "!bcd_vol!"=="%%i" (set "l0=*!l0:~1!" ))
- if defined bcd_ltr (if /i "!bcd_ltr!"=="!ltr!" (set "l0=*!l0:~1!" && set "bcd_vol=%%i"))
- SET info=!l0:~-9! && set info=!info: =!
- if defined bcdedit_error (
- CALL:STR_X STR2 !info!
- if not errorlevel 1 (set "l0=*!l0:~1!" && set "BCD_VOL=%%i" && set "bcd_ltr=!ltr!" )
- )
- echo !l0!
- if "%%i"=="###" echo !分割线!
- )
- )
- )
- echo !分割线!
- if not defined bcd_vol (
- echo Can not find System_volume ... Error!
- exit /b 1
- )
- call:unltrs2
- rem set ltrs=Z
- exit /b 0
- :init_end
- rem 执行某一脚本--并显示BCD_VOL信息---------------
- :load_script
- call:%1
- for /f "delims=" %%h in ('diskpart /s %tempfile%') do (
- set "l0=%%h"
- for /f "tokens=1,2 delims= " %%r in ("!l0:~1!") do (
- call:str_x str1 %%r
- if not errorlevel 1 ( if /i not "%%s"=="###" (
- SET "ltr=!l0:~14,3!" && set "ltr=!ltr: =!"&& set Used_LTRs=!used_ltrs!,!ltr!
- ))
- if "!l0:~0,1!"=="*" (
- echo.
- echo !分割线!
- echo !l0!
- echo !分割线!
- set "bcd_ltr=!ltr!"
- )
- )
- )
- call:unltrs2
- rem set ltrs=Z
- exit /b 0
- :load_script
- rem diskpart_脚本-----------------------------------------------
- :script0
- >%tempfile% echo sele vol !BCD_VOL!
- exit /b
- :script0_end
- :script_up
- call:script0
- >>%tempfile% echo assign letter=!ltrs:~-1!
- >>%tempfile% echo list vol
- exit /b
- :script_up_end
- :script_down
- call:script0
- >>%tempfile% echo remove
- >>%tempfile% echo list vol
- exit /b
- :script_down_end
- rem 获取空余盘符-----------------------------------------------
- :unltrs2
- set ltrs=
- set ltrs0=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
- for %%c in (!used_ltrs!) do (set "ltrs0=!ltrs0:%%c=!")
- for %%c in (!ltrs0!) do (if not exist %%c:\ set "ltrs=!ltrs!%%c")
- exit /b
- :unltrs2_end
- rem 字符串对比-----------------------------------------------
- :str_x
- rem 两个变量,%1= str1 str2 str3 等 存储关键字的变量名,%2=数值
- rem 分别判断中文、英文 的关键字变量内容 与 数值是否一致,如果一致,返回1,否则返回0
- for %%x in (CN EN) DO ( if /i "!%%x_%1!"=="%2" exit /b 0)
- exit /b 1
- :str_x_end
- rem 通过bcdedit 获取bcd 分区----------------
- :bcdedit
- set "str9=device"
- for /f "tokens=1,2 delims= " %%c in ('bcdedit /enum {bootmgr}') do (
- if /i "%%c"=="!str9!" (
- set l0=%%d && set "l0=!l0: =!" && set "l0=!l0:volume=+!"
- if not "!l0:~-1!"==":" (
- for /f "tokens=2 delims=+" %%h in ("!l0!") do (
- set "bcd_vol=%%h"
- exit /b 0
- )
- ) ELSE (
- set "bcd_ltr=!l0:~-2,1!"
- exit /b 0
- )
- )
- )
- exit /b 1
- :bcdedit_end
复制代码
提示 回车 才 挂载、卸载,而不是自动挂载,卸载,就是为了 以防万一的。如果输入了 x 就 退出了。
|
|