Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB question about WscriptShell.Exec

Status
Not open for further replies.

HycHyc

Technical User
Aug 25, 2011
2
DE
Hello all,
I want to display in my script ONLY IP addresses of network cards. From command line I can achieve this running 'ipconfig | find "IP"'. Is it possible to achieve the same using WScript.Shell.Exec command in VBS?
When I trying to run something like this

et objShell = CreateObject( "WScript.Shell" )
Set objScriptExec = objShell.Exec("ipconfig | find "IP"")

I receive errors :-( Please help.
 
I though it might be that your quotes inside of quotes aren't excaped with...quotes

Code:
set objScriptExec = objShell.Exec([blue]"ipconfig | find "[red]"IP"[/red]"[/blue])

but I got errors too. Perhaps it's because the .Exec method doesn't like pipes (|)? Run a regular ipconfig and iterate the output looking for IPs

Code:
set objShell = CreateObject( "WScript.Shell" )
set objScriptExec = objShell.Exec("ipconfig")

do while not objScriptExec.StdOut.AtEndOfStream
	strLine = objScriptExec.StdOut.ReadLine
	if (inStr(strLine, "IPv4 Address")) then
		intPos = inStr(strLine, ":") + 1
		strIP = mid(strLine, intPos)
		strIPs = strIPs & vbNewLine & strIP
	end if
loop

msgbox strIPs

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
About quotes I know, i use them because 'find' only in that way can have arguments. I have tried also 'findstr', I shouldn't use there quotes, but then objScriptExec don't want to work properly.
Anyway, i tried to do it Your way and everything works great. Thanks :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top