Prev: use ConnectObject without WScript?
Next: Runas
From: axtens on 4 Jan 2006 21:07 Or else Function GetMac( sDevice ) Dim cItems Dim oItem Dim sResult sResult = "" On Error Resume Next Set oWMI = GetObject("winmgmts:\\" & sDevice & "\root\cimv2") If Err.Number = 0 Then Set cItems = oWMI.ExecQuery( "Select * from Win32_NetworkAdapterConfiguration" ) For Each oItem in cItems 'WScript.echo oItem.Name sResult = sResult & oItem.Caption & "~" & oItem.MACAddress & "^" Next sResult = Mid( sResult, 1, Len( sResult ) - 1 ) End If Err.Clear On Error Goto 0 GetMac = sResult End Function sPC = "PC003333" WScript.StdOut.Write "GetMac of " & sPC & ": " WSCript.Echo GetMac( sPC ) yields: GetMac of PC003333: [00000001] Intel(R) PRO/1000 CT Network Connection~00:0D:61:69:86:7E^[00000002] 1394 Net Adapter~^[00000003] RAS Async Adapter~^[00000005] WAN Miniport (L2TP)~^[00000006] WAN Miniport (PPTP)~50:50:54:50:30:30^[00000007] WAN Miniport (PPPOE)~33:50:6F:45:30:30^[00000008] Direct Parallel~^[00000009] WAN Miniport (IP)~^[00000010] Packet Scheduler Miniport~D6:DC:20:52:41:53^[00000011] 1394 Net Adapter~F2:FC:74:0C:C6:19 .... Bruce
From: lmossolle@nc.rr.com on 6 Jan 2006 16:57 try this!!! strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colAdapters = objWMIService.ExecQuery _ ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") n = 1 WScript.Echo For Each objAdapter in colAdapters WScript.Echo "Network Adapter " & n WScript.Echo "=================" WScript.Echo " Description: " & objAdapter.Description WScript.Echo " Physical (MAC) address: " & objAdapter.MACAddress WScript.Echo " Host name: " & objAdapter.DNSHostName If Not IsNull(objAdapter.IPAddress) Then For i = 0 To UBound(objAdapter.IPAddress) WScript.Echo " IP address: " & objAdapter.IPAddress(i) Next End If If Not IsNull(objAdapter.IPSubnet) Then For i = 0 To UBound(objAdapter.IPSubnet) WScript.Echo " Subnet: " & objAdapter.IPSubnet(i) Next End If If Not IsNull(objAdapter.DefaultIPGateway) Then For i = 0 To UBound(objAdapter.DefaultIPGateway) WScript.Echo " Default gateway: " & _ objAdapter.DefaultIPGateway(i) Next End If WScript.Echo WScript.Echo " DNS" WScript.Echo " ---" WScript.Echo " DNS servers in search order:" If Not IsNull(objAdapter.DNSServerSearchOrder) Then For i = 0 To UBound(objAdapter.DNSServerSearchOrder) WScript.Echo " " & objAdapter.DNSServerSearchOrder(i) Next End If WScript.Echo " DNS domain: " & objAdapter.DNSDomain If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder) WScript.Echo " DNS suffix search list: " & _ objAdapter.DNSDomainSuffixSearchOrder(i) Next End If WScript.Echo WScript.Echo " DHCP" WScript.Echo " ----" WScript.Echo " DHCP enabled: " & objAdapter.DHCPEnabled WScript.Echo " DHCP server: " & objAdapter.DHCPServer If Not IsNull(objAdapter.DHCPLeaseObtained) Then utcLeaseObtained = objAdapter.DHCPLeaseObtained strLeaseObtained = WMIDateStringToDate(utcLeaseObtained) Else strLeaseObtained = "" End If WScript.Echo " DHCP lease obtained: " & strLeaseObtained If Not IsNull(objAdapter.DHCPLeaseExpires) Then utcLeaseExpires = objAdapter.DHCPLeaseExpires strLeaseExpires = WMIDateStringToDate(utcLeaseExpires) Else strLeaseExpires = "" End If WScript.Echo " DHCP lease expires: " & strLeaseExpires WScript.Echo WScript.Echo " WINS" WScript.Echo " ----" WScript.Echo " Primary WINS server: " & objAdapter.WINSPrimaryServer WScript.Echo " Secondary WINS server: " & objAdapter.WINSSecondaryServer WScript.Echo n = n + 1 Next Function WMIDateStringToDate(utcDate) WMIDateStringToDate = CDate(Mid(utcDate, 5, 2) & "/" & _ Mid(utcDate, 7, 2) & "/" & _ Left(utcDate, 4) & " " & _ Mid (utcDate, 9, 2) & ":" & _ Mid(utcDate, 11, 2) & ":" & _ Mid(utcDate, 13, 2)) End Function "axtens" wrote: > Or else > Function GetMac( sDevice ) > Dim cItems > Dim oItem > Dim sResult > > sResult = "" > > On Error Resume Next > Set oWMI = GetObject("winmgmts:\\" & sDevice & "\root\cimv2") > If Err.Number = 0 Then > Set cItems = oWMI.ExecQuery( "Select * from > Win32_NetworkAdapterConfiguration" ) > For Each oItem in cItems > 'WScript.echo oItem.Name > sResult = sResult & oItem.Caption & "~" & oItem.MACAddress & "^" > Next > > sResult = Mid( sResult, 1, Len( sResult ) - 1 ) > End If > Err.Clear > On Error Goto 0 > > GetMac = sResult > End Function > > sPC = "PC003333" > WScript.StdOut.Write "GetMac of " & sPC & ": " > WSCript.Echo GetMac( sPC ) > > yields: > GetMac of PC003333: [00000001] Intel(R) PRO/1000 CT Network > Connection~00:0D:61:69:86:7E^[00000002] 1394 Net Adapter~^[00000003] > RAS Async Adapter~^[00000005] WAN Miniport (L2TP)~^[00000006] WAN > Miniport (PPTP)~50:50:54:50:30:30^[00000007] WAN Miniport > (PPPOE)~33:50:6F:45:30:30^[00000008] Direct Parallel~^[00000009] WAN > Miniport (IP)~^[00000010] Packet Scheduler > Miniport~D6:DC:20:52:41:53^[00000011] 1394 Net > Adapter~F2:FC:74:0C:C6:19 > > .... Bruce > >
From: Deephazz on 7 Jan 2006 04:31
Thank you lmossolle ! The code sample : " Set colAdapters = objWMIService.ExecQuery _ ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") " works great on client computer. In fact the following snippet is enough : =================== strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colAdapters = objWMIService.ExecQuery _ ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") n = 1 WScript.Echo For Each objAdapter in colAdapters WScript.Echo " Physical (MAC) address: " & objAdapter.MACAddress WScript.Echo " Host name: " & objAdapter.DNSHostName n = n + 1 Next ======================== Thank you all for replying. Regards. |