的SystemInfo - 通过获取计算机CMD系统模型 - 额外空间的bug [英] SystemInfo - Get computer System Model via CMD - Extra spaces bug

查看:243
本文介绍了的SystemInfo - 通过获取计算机CMD系统模型 - 额外空间的bug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得通过批处理文件的计算机系统模型类型。
为了这个,我已经创建了这个脚本:

I'm trying to get a Computer System Model type via Batch file. for this i've created this script:

systeminfo | find "System Model" > %temp%\TEMPSYSINFO.txt
for /F "tokens=2 delims=:" %%a in (%temp%\TEMPSYSINFO.txt) do set SYSMODEL=%%a
del %temp%\TEMPSYSINFO.txt
set SYSMODEL=%SYSMODEL:~1%
echo %SYSMODEL% >%temp%\SYSMODEL.txt
del %temp%\SYSMODEL.txt
set "Line1=*** System Model: %SYSMODEL%"
echo %Line1%

但是当我运行它,我得到额外的空格:

but when I run it i get extra spaces:

*** System Model:              OptiPlex 9010

任何想法,我应该如何解决呢?

Any idea how can I fix it?

推荐答案

您正在做硬盘的方式。使用 WMIC 。这是一个很大更快,更复杂的刮。

You're doing it the hard way. Use wmic. It's a lot faster and less complicated to scrape.

for /f "tokens=2 delims==" %%I in ('wmic computersystem get model /format:list') do set "SYSMODEL=%%I"
set "Line1=*** System Model: %SYSMODEL%"
echo %Line1%

WMIC ,您可以查询各种整齐的WMI垃圾。 WMIC /?了解更多信息。

wmic lets you query all sorts of neat wmi garbage. wmic /? for more info.

(每下模糊巴顿的答案OP的评论更新)

(updated per OP's comment under Fuzzy Button's answer)

这篇关于的SystemInfo - 通过获取计算机CMD系统模型 - 额外空间的bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆