Solved I am trying to create a a batch file using WMIC

July 19, 2017 at 11:35:02
Specs: Windows 7
I am trying to create a a batch file using WMIC that will poll the version of the system BIOS and update automatically if necessary.. The issue I am having is the message "goto was unexpected at this time." Any assistance your can provide will be truly appreciated. Here is the script:
@Echo Off
Echo.
FOR /F "tokens=*" %%A IN ('WMIC BIOS Get SMBIOSBIOSVERSION /Value') DO SET BIOS.%%A
IF %SMBIOSBIOSVERSION% == "N01 Ver. 02.17" goto image
IF %SMBIOSBIOSVERSION% == "K01 v02.85" goto 299
IF %SMBIOSBIOSVERSION% == "K01 v02.90" goto 299
IF %SMBIOSBIOSVERSION% == "K01 v02.99" goto 304
IF %SMBIOSBIOSVERSION% == "K01 v03.04" goto image

:299
Echo the system BIOS needs to be updated to version 2.99
Pause
:304
Echo the system BIOS needs to be updated to version 3.04
Pause
:Image
Echo the system BIOS is up to date.
Pause

message edited by mbmaniac


See More: I am trying to create a a batch file using WMIC

Reply ↓  Report •

#1
July 22, 2017 at 18:45:09
First problem: [looks like there are more]
WMIC is classic microsoft dips---.
It puts out the hoped-for line & a bunch of clutter, so your var is not getting set.
Try this:

FOR /F "tokens=*" %%A IN ('WMIC BIOS Get SMBIOSBIOSVERSION /Value ^| find "BIOS"') DO SET BIOS.%%A

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#2
July 22, 2017 at 21:14:22
✔ Best Answer
No idea what this does:
FOR /F "tokens=*" %%A IN ('WMIC BIOS Get SMBIOSBIOSVERSION /Value') DO SET BIOS.%%A

but M2 has the gist. I'll add:

FOR /F "tokens=2 delims==" %%A IN ('WMIC BIOS Get SMBIOSBIOSVERSION /Value ^|find "BIOS"') DO set x=%%A
echo bios version is [%x%]

The only other thing is to put quotes around both sides of the IF arguments if they don't already have them, like:

IF "%x%" == "N01 Ver. 02.17" goto image


Reply ↓  Report •

#3
July 23, 2017 at 12:38:59
nbrane: No idea what this does
In theory, it'd set %BIOS.SMBIOSBIOSVersion% on successful execution. That should help you figure out the first issue (out of 3 to 5, depending on how you count) with OP's script.

How To Ask Questions The Smart Way


Reply ↓  Report •

Related Solutions

#4
July 27, 2017 at 03:38:49
In case we get follow-through. which seems unlikely, the second line is testing [incorrectly] for a var which is not getting set.
Not in this script, anyway.

2017-07-27 17:38:14.10 GMT +7

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#5
August 27, 2017 at 03:53:38
hmmm, it's strange, but I don't see some mistakes there

Reply ↓  Report •

#6
August 28, 2017 at 21:05:14
"I don't see some mistakes there"

Let's guess: you didn't try to make it work. You just looked and didn't see any mistakes.

Probably, same goes for OP.

Another amazing waste of resources.

2017-08-29 11:05:19.65 GMT +7

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#7
August 29, 2017 at 01:25:03
If I remember correctly, WMIC outputs in unicode and certain characters needs to be stripped from the output in order to make it work correctly in regular batch files. At least that's what worked for me whenever I had to parse input from WMIC.

Try this:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=2 delims==" %%Z in ('WMIC BIOS Get SMBIOSBIOSVERSION /Value') do (
	echo "%%Z"
	Echo.**%%Z**>tmp
	for /f %%C in (tmp) do (
		set SMBIOSBIOSVERSION=%%C
		set SMBIOSBIOSVERSION=!SMBIOSBIOSVERSION:~2,-3!
	)
        echo "!SMBIOSBIOSVERSION!"
	del /q "tmp"
)
REM Your code goes here

You can see there's a difference between %%Z and !SMBIOSBIOSVERSION!. The difference is that the "trash" included in the WMIC output has been stripped off. The "invisible" characters that have been stripped might be what's causing your error.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ


Reply ↓  Report •

Ask Question