We help IT Professionals succeed at work.
Get Started

VB Script Issue with Quotes - End of Statement Error

826 Views
Last Modified: 2012-09-05
The script below runs a standard netsh command to assign the IP and DNS settings for a network card named "Local" to dhcp.

..............

WScript.Echo "Assigning Address Range"

Set objShell = WScript.CreateObject("Wscript.Shell")
objShell.Run "netsh interface ip set address Local source=dhcp"
objShell.Run "netsh interface ip set dns Local source=dhcp"
Set objShell = Nothing

WScript.Echo "Completed.  Please reboot your laptop."
WScript.Quit

My problem is the network connection in windows is called AHDB LAN but when I change the script to reflect that name, putting AHDB LAN in quotes due to the space, it appears to break the script.

..........

Set objShell = WScript.CreateObject("Wscript.Shell")
objShell.Run "netsh interface ip set address "AHDB LAN" source=dhcp"
objShell.Run "netsh interface ip set dns "AHDB LAN" source=dhcp"

When I run it I get "Expected end of statement".

How can I amend the script to query the correct NIC adapter name.
Comment
Watch Question
Keep everyone healthy; Wear a mask - Social distance - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE