0

I am running the following command within a batch script:

netsh advfirewall firewall show rule name ="MyCustomRule"

And it gives out either a string "No rules match the specified criteria." or multiple rows.

I would like to be able to assign its output to a variable something like:

set a = output(netsh advfirewall firewall show rule name ="MyCustomRule")

Such that I can further do if "%a%" == "" . Is it possible?

1

2 Answers 2

1

Did you mean something like that :

@echo off
for /f "delims=" %%a in ('netsh advfirewall firewall show rule name^="MyCustomRule"') do (
    Set "Output=%%a"
)
Echo Output Result = "%OutPut%"
pause
Sign up to request clarification or add additional context in comments.

Comments

1

It's possible, although I doubt that it will be fun dealing with all the blanks in your string.

Another approach would be using the commands FIND or FINDST to check your output for the presence of a substring and then to do IF statements based on the %ERRORLEVEL% generated by these commands.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.