?
Solved

VB Script Issue with Quotes - End of Statement Error

Posted on 2012-08-13
2
Medium Priority
?
815 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.
0
Comment
Question by:Mdc2050
2 Comments
 
LVL 50

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 38288657
objShell.Run "netsh interface ip set address " & Asc(34) & "AHDB LAN" & Asc(34) & " source=dhcp"


and similar for the next one.
0
 
LVL 12

Expert Comment

by:Seaton007
ID: 38288682
Here you go:
Dim strInterface
strInterface = "AHDB LAN"

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "netsh interface ip set address " &  Chr(34) & strInterface  & Chr(34)  & " source=dhcp"
objShell.Run "netsh interface ip set dns " & Chr(34) & strInterface & Chr(34) & " source=dhcp"

Open in new window

I also added a variable called "strInterface" for the connection name to make things easier to modify for different connection names.

Or, if you prefer, you can also do it this way:
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"

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question