question

winprofessional avatar image
0 Votes"
winprofessional asked ·

Comparing strings in batch files

I am not sure of this is teh right forum to ask this question. If not, kindly direct me to the correct forum.

I am trying to call a WMI command from a batch file like below:

 for /f "tokens=2 delims==" %%f in ('wmic /namespace:\some command /value ^| find "="') do set "val=%%f"
 
 IF "%val%"==""( echo Null. Exiting...
   Exit /B
 )

The issue is if the WMI command didn't find the query result, then I expect the query to return an empty string. The value I am looking for is a string. So the above empty string comparison does not work so I am not getting the "Exiting...." statement. What is wrong here? What more is to done in the comparison? .The value I am looking for doesn't exist and the script says "No instances found" in command prompt. But I need to inform the user in a nice way. How do one does string or empty comparisons in batch files?

not-supported
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DSPatrick avatar image
0 Votes"
DSPatrick answered ·

QnA currently supports the products listed in right-hand pane (more to be added) Better to reach out to subject matter experts in dedicated forums over here.

https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG

(please don't forget to mark helpful replies as answer)

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.