2

I have written a script on Windows 7 which keeps giving me an error of "( was unexpected at this time." for the following code

if %vardns%=="NODNS" (
  netsh interface ipv4 set address name="%__ethAdapter.42%" source=static addr=%varip_old% mask=%varsubnet_old% gateway=%vargateway_old% gwmetric=1
) else (
  netsh interface ipv4 set address name="%__ethAdapter.42%" source=dhcp
)

I am not sure where the issue lies and have read many other posts. Any help would be kindly appreciated. Thanks in advance.

3
  • Looks ok to me is there more? - You need to correct to: if %vardns%==NODNS ( I.e. no quotes but I would not have thought that's causing that error Commented Jul 26, 2012 at 15:45
  • Check that the value of %vardns% doesn't have special characters. Commented Jul 26, 2012 at 15:50
  • Put ECHO ON before the command that is failing and then run the script. You will then be able to see what the command looks like after the variables are expanded and it hopefully will become more obvious where the problem lies. If you can't figure it out, post the expanded version. Commented Jul 26, 2012 at 15:59

1 Answer 1

3

You're getting this error because vardns is probably empty, and the interpreter unrolls this line to:

if =="NODNS" (

Which is illegal syntax.

What you've been advised to do is correct -- add quotation marks around %vardns%, like this:

if "%vardns%"=="NODNS" (

and it should work.

Sign up to request clarification or add additional context in comments.

1 Comment

The added quotation marks fixed it. Many thanks to the quick replies.

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.