运行批处理文件时出错 - 此级别的意外切换

时间:2016-09-08 07:19:17

标签: batch-file

我有以下批次代码,运行正常,输出正常,甚至保存罚款,但每次运行时我都会收到错误

  

此级别的意外切换

请你帮我理解为什么我会这样做,虽然命令按照需要运行,但这只是令人讨厌。

@echo off
if exist C:\dell\%computername%.csv del C:\dell\%computername%.csv
set outputfile="C:\dell\%computername%.csv"
for /f "delims== tokens=2" %%i in ('wmic os get csname /value') do SET CSNAME=%%i
for /f "delims== tokens=2" %%i in ('wmic os get caption /value') do SET CAPTION=%%i
for /f "delims== tokens=2" %%i in ('wmic computersystem get manufacturer /value') do SET MANUFACTURER=%%i
for /f "delims== tokens=2" %%i in ('wmic computersystem get model /value') do SET MODEL=%%i
for /f "delims== tokens=2" %%i in ('wmic os get osarchitecture /value') do SET OSBIT=%%i
for /f "delims== tokens=2" %%i in ('wmic cpu get name /value') do SET PROC=%%i
for /f "delims== tokens=2" %%i in ('wmic bios get softwareelementid /value') do SET BIOSVER=%%i
for /f "delims== tokens=2" %%i in ('wmic computersystem get totalphysicalmemory /value') do SET MEM=%%i
for /f "delims== tokens=2" %%i in ('wmic ntdomain get dnsforestname /value') do SET DOMAIN=%%i
for /f "delims== tokens=2" %%i in ('wmic bios get serialnumber /value') do SET SERVICETAG=%%i
for /f "delims== tokens=2" %%i in ('wmic computersystem get username /value') do SET USERNAME=%%i
for /f "delims== tokens=2" %%i in ('WMIC path Win32_VideoController get Name /value') do SET GRAPHICCARD=%%i
for /f "delims== tokens=2" %%i in ('wmic sounddev get productname /value') do SET AUDIODEVICE=%%i
for /f "delims== tokens=2" %%i in ('WMIC Path Win32_Battery Get status /value') do SET BATTERYSTATUS=%%i
for /f "delims== tokens=2" %%i in ('wmic cdrom get caption /value') do SET CDROM=%%i
for /f "delims== tokens=2" %%i in ('wmic path win32_pointingdevice get hardwaretype /value') do SET MOUSE=%%i
for /f "delims== tokens=2" %%i in ('wmic path win32_keyboard get description /value') do SET KEYBOARD=%%i
for /f "delims== tokens=2" %%i in ('wmic path win32_desktopmonitor /value') do SET MONITOR=%%i
for /f "delims== tokens=2" %%i in ('wmic computersystem get numberoflogicalprocessors /value') do SET PROCESSORNUM=%%i
for /f "delims== tokens=2" %%i in ('wmic path win32_logicaldisk where "drivetype = 3" get size /value') do SET HDDSIZE=%%i
for /f "delims== tokens=2" %%i in ('wmic nicconfig get dhcpserver /value') do SET DHCP=%%i

echo Compname,OsName,Manufacturer,Model,OsBit,Proc,BiosVersion,Memory,Domain,ServiceTag,UserName,GraphicCard,AudioDevice,BatteryStatus,CDROM,Mouse, Keyboard,Monitor,NumOfProc,HDDSize,DHCP>>%outputfile%
echo %CSNAME%,%CAPTION%,%MANUFACTURER%,%MODEL%,%OSBIT%,%PROC%,%BIOSVER%,%MEM%,%DOMAIN%,%SERVICETAG%,%USERNAME%,%GRAPHICCARD%,%AUDIODEVICE%,%BATTERYSTATUS%,%CDROM%,%MOUSE%,%KEYBOARD%,%MONITOR%,%PROCESSORNUM%,%HDDSIZE%,%DHCP%>>%outputfile%

1 个答案:

答案 0 :(得分:1)

作为CristiFati comments,引发错误的命令是

wmic path win32_desktopmonitor /value

原因显示在wmic command line reference中:/VALUE不是wmic的开关,而是GET动词的开关。由于您未在此命令中使用任何动词,因此无法包含该开关。