Share This Post

VB/WMI script to read remote registry to get IP address information

Here is a VB/WMI script to read remote registry to get IP address information for server. First, it uses WMI to read a string and to determine which network card to use. Then it will read a multi-string value to get the IP addresses. The IP address is actually stored in an Array, we will need to use Join function to place the elements in a string and then use split function to get the specific Octet we are interested.

GetIPInfo.vbs:

On Error Resume Next

strComputer = Inputbox ("Enter The Server Name")

Const HKEY_LOCAL_MACHINE = &H80000002

‘Use WMI provider to connect to remote registry
Set oReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

‘Determine which network card to use
sNICSearch = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\1" ‘the number may vary”
sServiceName = "ServiceName"
oReg.GetStringValue _
HKEY_LOCAL_MACHINE,sNICSearch,sServiceName,strValue

‘To get the IP address
sInterfaceskey = "System\CurrentControlSet\Services\TCPIP\Parameters\Interfaces\"
sIPAddressKey = sInterfacesKey & strValue
sIPAddress = "IPAddress"

oReg.GetMultiStringValue _
HKEY_LOCAL_MACHINE,sIPAddressKey,sIPAddress,arrValues

‘To manipulate the array(Join & Split) to get the Octets Information
strDelimiter = "."
strIPAddress = Join(arrValues, strDelimiter)

Wscript.Echo strIPAddress

strIPOctets = split (strIPAddress, strDelimiter)
ThirdOctet = strIPOctets (2)

Wscript.Echo ThirdOctet

Share This Post

Ying Li obtained a Master degree of Medicine in China and worked in the medical field before he came to the states in 1996. He made the career switch from troubleshooting people to troubleshooting computers after he came to the states. Not entirely a surprise there, if you know that his second preference for college is Mathematics. Ying is two times Admin Framework MVP awardee (2007-2008).His previous employment experience in the US includes UUNET, MCI WorldCom. MMC (Marsh & McLennan Companies), Merrill Lynch. He is currently employed by Related Companies as a Senior Infrastructure Engineer. He is proficient in virtually all Microsoft products (Office/Back office). His craving for efficiency naturally leads him to scripting, automation and before you know it, PowerShell! He is currently a MCSE (NT4, 2000, 2003) and MCITP Server Administrator. Ying enjoys wines and love to travel. His non work related passion is to advocate Health Living!

Leave a Reply