i want to find the ip address fo the computer.. how would i do it
Here is a function I use that runs on any 32-bit client: ================ Function GetIPAddresses() ' Based on a Michael Harris script, modified by Torgeir Bakken ' ' Returns array of IP Addresses as output ' by IPConfig or WinIPCfg... ' ' Win98/WinNT have IPConfig (Win95 doesn't) ' Win98/Win95 have WinIPCfg (WinNt doesn't) ' ' Note: The PPP Adapter (Dial Up Adapter) is ' excluded if not connected (IP address will be 0.0.0.0) ' and included if it is connected. Dim objShell, objFSO, objEnv, strWorkFile, objFile Dim arrData, intIndex, n, arrIPAddresses, arrParts Set objShell = CreateObject("wscript.shell") Set objFSO = CreateObject("scripting.filesystemobject") Set objEnv = objShell.Environment("PROCESS") If (objEnv("OS") = "Windows_NT") Then strWorkFile = objEnv("TEMP") & "\" & objFSO.GetTempName objShell.Run "%comspec% /c IPConfig >" & Chr(34) _ & strWorkFile & Chr(34), 0, True Else ' WinIPCfg in batch mode sends output to ' filename WinIPCfg.out strWorkFile = "WinIPCfg.out" objShell.Run "WinIPCfg /batch", 0, True End If Set objShell = Nothing Set objFile = objFSO.OpenTextFile(strWorkFile) arrData = Split(objFile. ReadAll, vbCrLf) objFile.Close Set objFile = Nothing objFSO.DeleteFile strWorkFile Set objFSO = Nothing arrIPAddresses = Array() intIndex = -1 For n = 0 To UBound(arrData) If (InStr(arrData(n), "IP Address") > 0) Then arrParts = Split(arrData(n), ":") If (InStr(Trim(arrParts(1)), "0.0.0.0") = 0) Then intIndex = intIndex + 1 ReDim Preserve arrIPAddresses(intIndex) arrIPAddresses(intIndex)= Trim(CStr(arrParts(1))) End If End If Next GetIPAddresses = arrIPAddresses End Function ========== If the client has Windows XP or above you can use the Win32_PingStatus class for this. See this link: http://www.microsoft.com/technet/scriptcenter/scripts/hardware/monitor/hwmovb07.mspx?mfr=true You would revise this to return Address. Note that there can be more than one.
Strangely, I cannot find where people use Win32_PingStatus to retrieve the IP address of a computer. I found the following works for me, but I cannot say if it will work in all situations: ======== Set objNetwork = CreateObject("Wscript.Network") strComputer = objNetwork.ComputerName Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colComputers = objWMIService.ExecQuery _ ("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'") For Each objComputer In colComputers Wscript.Echo objComputer.ProtocolAddress Next ======== On XP clients, this retrieves the IPv4 IP addresses, on Vista it retrieves the IPv6 addresses. Off hand I don't know how to retrieve the IPv4 addresses on Vista. I also see that the function I posted earlier using IPConfig fails on Vista clients. All of this needs to be reinvented unfortunately. A revised function that worked on Vista for me simply replaced this statement in the GetIPAddresses function: If (InStr(arrData(n), "IP Address") > 0) Then with the following: If (InStr(arrData(n), "IPv4 Address") > 0) Then Finding a method that works on all clients may be a challenge.
sMachineName = "." Set objWMIService = GetObject("winmgmts:\\" & sMachineName & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled='True'") For Each objItem In colItems wscript.echo Join(objItem.IPAddress, ",") Next
Much better. -- Richard Mueller Microsoft MVP Scripting and ADSI Hilltop Lab - http://www.rlmueller.net --