标题: [系统相关] [已解决]wmic memorychip命令,输出结果,赋值给变量。批处理代码如何写? [打印本页]
作者: ygqiang 时间: 2024-1-18 21:00 标题: [已解决]wmic memorychip命令,输出结果,赋值给变量。批处理代码如何写?
本帖最后由 ygqiang 于 2024-1-20 12:06 编辑
[已解决]wmic memorychip get manufacturer这个命令,输出结果第二第三第四行等等,赋值给变量。批处理代码如何写?
命令显示结果如下:(1根内存条)
Manufacturer
Corsair
或者显示结果如下:(2根不同品牌的内存条)
Manufacturer
Corsair
Kinston
作者: ygqiang 时间: 2024-1-18 21:01
本帖最后由 ygqiang 于 2024-1-20 12:11 编辑
- @echo off
- setlocal enabledelayedexpansion
-
- COLOR 04
- COLOR 84
-
- COLOR f4
- COLOR fc
- COLOR 7c
- COLOR 74
- echo.
- echo.
- echo --------------硬盘信息如下:
- for /f "tokens=2 delims==" %%a in ('"wmic DiskDrive where MediaType='Fixed hard disk media' get Caption /value"') do set /a DiskQuantity+=1
- echo 硬盘数量:【%DiskQuantity% 块】
- echo.
- set "StrDrive="
- for /f "tokens=1* delims==" %%a in ('"wmic DiskDrive where MediaType='Fixed hard disk media' get Model,Size /value | findstr ="') do (
- if "%%a" == "Model" (
- for /f %%i in ("%%b") do (
- set StrDrive=!StrDrive!,品牌:%%i
- )
- ) else if "%%a" == "Size" (
- for /f "delims=" %%i in ("%%b") do (
- set SizeGB=%%i
- set /a SizeGB=!SizeGB:~, -6!/1000
- set StrDrive=!StrDrive!,容量:!SizeGB!GB
- set "StrDrive=!StrDrive:~1!"
- echo,!StrDrive!
- set "StrDrive="
-
- )
- )
- )
-
- echo.
- echo.
-
- @echo off
- setlocal enabledelayedexpansion
- echo ============内存信息如下:
- for /f "tokens=2 delims==" %%a in ('"wmic memorychip Get Tag /value"') do set /a MemoryQuantity+=1
- echo 内存数量:【%MemoryQuantity% 条】
- echo.
- wmic memorychip get manufacturer
- echo.
- echo 内存品牌:
- for /f "tokens=2 delims==" %%a in ('wmic memorychip get manufacturer /value ^| findstr "="') do (
- set "MemoryFacturer=%%a"
- echo !MemoryFacturer!
- )
- echo.
- for /f "tokens=1-2 delims==" %%a in ('wmic MemoryChip get Capacity^,Speed /value ^| findstr "="') do (
- if "%%a" == "Capacity" (
- for %%c in (%%b) do (
- set "MemCap=%%c"
- )
- ) else if "%%a" == "Speed" (
- for %%c in (%%b) do (
- set "MemSpd=%%c"
- )
- for /f %%i in ('powershell "!MemCap!/(1024*1024*1024)"') do (
- set "MemCap=%%i"
- )
-
- echo 内存容量:!MemCap!GB
- echo 内存频率:!MemSpd!
- echo.
- )
- )
- pause >nul 2>nul
复制代码
作者: ShowCode 时间: 2024-1-18 21:14
回复 1# ygqiang - @echo off
- for /f "tokens=2 delims==" %%a in ('wmic memorychip get manufacturer /value ^| findstr "="') do (
- set "MemoryFacturer=%%a"
- )
- echo,%MemoryFacturer%
- pause
复制代码
作者: ygqiang 时间: 2024-1-18 21:30
回复 3# ShowCode
谢谢。
如果wmic memorychip get manufacturer 命令结果显示如下:
Manufacturer
Corsair
Kinston
你这个命令代码,也会正常显示吗?
作者: /zhqsystem/zhq 时间: 2024-1-18 22:24
- for /f "delims=" %%a in ('"Wmic.exe Memorychip get DeviceLocator /format:list"')do for /f "tokens=1,* delims==" %%a in ("%%a")do for /f "delims=" %%d in ('"Wmic.exe Memorychip get BankLabel,Capacity,Caption,DeviceLocator,FormFactor,PartNumber,Manufacturer,Speed,TotalWidth,TypeDetail /format:list"')do for /f "tokens=1,* delims==" %%d in ("%%d")do echo,内存信息: %%b %%d=%%e
复制代码
作者: newswan 时间: 2024-1-18 22:31
powershell 比批处理方便多了
参考 http://www.bathome.net/viewthread.php?tid=68303&extra=
作者: ShowCode 时间: 2024-1-19 08:20
回复 4# ygqiang
请亲自试试吧,遇到问题咱们再继续探讨。
作者: ppll2030 时间: 2024-1-19 10:03
回复 3# ShowCode
直接循环输出就是了。当然,同品牌也会对应根数输出。- @echo off
- for /f "tokens=2 delims==" %%a in ('wmic memorychip get manufacturer /value ^| findstr "="') do (
- echo, %%a
- )
- pause
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |