troubleshooting Question

Syntax for windows VB script to find IPAddress

Avatar of Steve7423
Steve7423Flag for Canada asked on
Microsoft DOSCitrixMicrosoft Legacy OS
11 Comments1 Solution715 ViewsLast Modified:
I seem to be having a hard time understand how to run the following VB script and getting this to work.  This is my first attempt at VB scripting and I'm a little confused.

I run the following as a .bat file and it works.  

IPCONFIG |FIND "IP" > %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
set IP=%IP:~1%
echo %IP% >%temp%\ip.txt
echo The current IP address is "%IP%"

However, when I run it as a .vbs I get character errors.
I've tried to make changes as you can see but I just keep getting deeper in muck.

could someone please help me correct the syntax so it can be run in a VBS.

dim ip

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run(IPCONFIG invokes FIND "IP" > %temp%\TEMPIP.txt)
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
set IP=%IP:~1%

msgbox "The current IP address is" & "%IP%"
ASKER CERTIFIED SOLUTION
cantoris

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros