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.
You’re getting this error because
vardnsis probably empty, and the interpreter unrolls this line to:Which is illegal syntax.
What you’ve been advised to do is correct — add quotation marks around
%vardns%, like this:and it should work.