Home > OS >  Reading the answer from the query "wmic"
Reading the answer from the query "wmic"

Time:10-24

I can't cope with reading the return code from the command

wmic computersystem where name="%computername%" rename name=aaaaa

The point is, I want to notify the error to the person who will be using it without administrator privileges.

How to send "ReturnValue = 5" to errorlevel or goto?

cmd screen

CodePudding user response:

How to send "ReturnValue = 5" to errorlevel or goto?

for /f "skip=2 tokens=2 delims==;" %%a in ('wmic computersystem where name^="%computername%" rename name^=aaaaa 2^>nul') do cmd /c exit %%a
echo %errorlevel%

or with GOTO:

wmic computersystem where name="AKOYA-P4" rename name=aaa |find "ReturnValue = 5;" >nul && goto :label
  • Related