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

[其他] PE里确定系统版本 求助批处理变量调用问题 for 里面

PE里确定系统版本 求助一个变量调用问题 for 里面

问题在第 19-22行的代码位置

请大神们指教,优化代码

谢谢
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "$5.1.26=WinXP"
  4. set "$5.2.00=WinXP 64       "
  5. set "$6.0.60=Vista /S2008   "
  6. set "$6.1.76=Win7  /S2008 R2"
  7. set "$6.2.92=Win8  /S2012   "
  8. set "$6.3.96=Win8.1/S2012R2 "
  9. set "$10.0.1=Win10 /S2016-9 "
  10. set "$10.0.2=Wind11/S2022   "
  11. :: 遍历磁盘,确定盘符占用,并返回系统版本
  12. for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  13.   if exist %%a:\ (
  14.     if exist "%%a:\windows\system32\version.dll" (
  15.         echo %%a
  16.         for /f "tokens=2 delims==" %%b in ('wmic datafile where Name^="%%a:\\Windows\\explorer.exe" get Version /value') do (
  17.             call echo %%b
  18.             set "tmp=%%b"
  19.             set "x=!tmp:~0,6!"
  20.             set "xx=$!x!"
  21.         )
  22.         for /f "tokens=2 delims==" %%b in ('wmic datafile where Name^="%%a:\\Windows\\System32\\version.dll" get Version /value') do (call echo %%b)
  23.         if exist "%%a:\boot\memtest.ext" (echo BIOS)  else (echo UEFI)
  24.     )
  25.   )
  26. )
  27. echo !x!
  28. echo !xx!
  29. echo --------------
  30. set
  31. PAUSE>NUL
复制代码

回复 1# dong3626
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "$5.1.26=WinXP"
  4. set "$5.2.00=WinXP 64       "
  5. set "$6.0.60=Vista /S2008   "
  6. set "$6.1.76=Win7  /S2008 R2"
  7. set "$6.2.92=Win8  /S2012   "
  8. set "$6.3.96=Win8.1/S2012R2 "
  9. set "$10.0.1=Win10 /S2016-9 "
  10. set "$10.0.2=Wind11/S2022   "
  11. REM 遍历磁盘,确定盘符占用,并返回系统版本
  12. for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  13.     if exist "%%a:\windows\system32\version.dll" (
  14.         echo %%a
  15.         for /f "tokens=2 delims==" %%b in ('wmic datafile where Name^="%%a:\\Windows\\explorer.exe" get Version /value') do (
  16.             echo,%%b
  17.             set "tmp=%%b"
  18.             set "x=!tmp:~0,6!"
  19.             call set "xx=%%$!x!%%"
  20.         )
  21.         for /f "tokens=2 delims==" %%b in ('wmic datafile where Name^="%%a:\\Windows\\System32\\version.dll" get Version /value') do (
  22.             echo,%%b
  23.         )
  24.         if exist "%%a:\boot\memtest.ext" (
  25.             echo BIOS
  26.         ) else (
  27.             echo UEFI
  28.         )
  29.     )
  30. )
  31. echo,!x!
  32. echo,!xx!
  33. pause
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

本帖最后由 dong3626 于 2023-4-19 22:00 编辑
回复  dong3626
Batcher 发表于 2023-4-19 21:41


感谢回答

那部分代码应该能简化,只是想获得系统版本

请赐教,这是哪一部分知识   再次谢谢

经指教,代码优化为:
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "$5.1.26=WinXP"
  4. set "$5.2.00=WinXP 64       "
  5. set "$6.0.60=Vista /S2008   "
  6. set "$6.1.76=Win7  /S2008 R2"
  7. set "$6.2.92=Win8  /S2012   "
  8. set "$6.3.96=Win8.1/S2012R2 "
  9. set "$10.0.1=Win10 /S2016-9 "
  10. set "$10.0.2=Wind11/S2022   "
  11. :: 遍历磁盘,确定盘符占用,并返回系统版本
  12. for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  13.   if exist %%a:\ (
  14.     if exist "%%a:\windows\system32\version.dll" (
  15.         for /f "tokens=2 delims==" %%b in ('wmic datafile where Name^="%%a:\\Windows\\explorer.exe" get Version /value') do (
  16.             set "tmp=%%b"
  17.             set "x=!tmp:~0,6!"
  18.             call set "xx=%%$!x!%%"
  19.             set pf=%%a
  20.             echo !pf! 盘存在系统 !xx!
  21.         )
  22.         if exist "%%a:\boot\memtest.ext" (echo %%a 盘引导方式 BIOS)  else (echo %%a 盘引导方式 UEFI)
  23.     )
  24.   )
  25. )
  26. echo --------------
  27. PAUSE>NUL
复制代码

TOP

回复 3# dong3626


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

TOP

7和10正常,xp出错

xp
6.00.2900.5512

7
6.1.7600.17514

10
10.0.14393.0

TOP

回复 5# 807979023

网上找的版本号
我这没有xp系统

请自行验证

居然还有xp系统,佩服

TOP

改了一句,好像可以了.

@echo off&color 1f&echo.
setlocal enabledelayedexpansion

set "$5.1.26=winXP "
set "$6.1.76=win7  "
set "$6.2.92=win8  "
set "$6.3.96=win8.1"
set "$10.0.1=win10 "
set "$10.0.2=wind11"

:: 遍历磁盘,确定盘符占用,并返回系统版本
for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  if exist %%a:\ (
    if exist "%%a:\windows\system32\version.dll" (
      if /i not exist "%%a:\windows\syswow64" (set vx=x32)else (set vx=x64)
      for /f "tokens=2 delims==" %%b in ('wmic datafile where Name^="%%a:\\Windows\\System32\\version.dll" get Version /value') do (
        set "tmp=%%b"
        set "x=!tmp:~0,6!"
        call set "xx=%%$!x!%%"
        set pf=%%a
        echo !pf!盘 !xx! !vx!
      )
    )
  )
)
echo.&echo 按任意键退出...&pause >nul&exit

TOP

这里wmic结果和ver应该一样的吧

TOP

ver只能查当前系统,多系统好像查不到,我硬盘上有3个系统。

TOP

返回列表