![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Read MTU value for each adapter Helllo, I have script that reads information for each network adapter. To make the script run, I need to add "on error resume next"... I don't feel comfortable doing this, but otherwise it doesnt work at all. But my question is the following: How could I read the MTU value for a network adapter? There exists a .MTU property ( http://msdn.microsoft.com/en-us/libr...17(VS.85).aspx ) - but I get no value for this. Here is the code: on Error Resume Next '** without this, the script crashes .... Const wbemFlagReturnImmediately = &h10 Const wbemFlagForwardOnly = &h20 strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly) For Each objItem In colItems WScript.Echo "Caption: " & objItem.Caption WScript.Echo "IPEnabled: " & objItem.IPEnabled strDefaultIPGateway = Join(objItem.DefaultIPGateway, ",") WScript.Echo "DefaultIPGateway: " & strDefaultIPGateway WScript.Echo "Description: " & objItem.Description WScript.Echo "DHCPEnabled: " & objItem.DHCPEnabled WScript.Echo "DHCPServer: " & objItem.DHCPServer WScript.Echo "DNSDomain: " & objItem.DNSDomain WScript.Echo "DNSHostName: " & objItem.DNSHostName strDNSServerSearchOrder = Join(objItem.DNSServerSearchOrder, ",") WScript.Echo "DNSServerSearchOrder: " & strDNSServerSearchOrder WScript.Echo "Index: " & objItem.Index strIPAddress = Join(objItem.IPAddress, ",") WScript.Echo "IPAddress: " & strIPAddress strIPSubnet = Join(objItem.IPSubnet, ",") WScript.Echo "IPSubnet: " & strIPSubnet WScript.Echo "MTU: " & objItem.MTU '** always empty... WScript.Echo "*************" Next Any idea how I could read the MTU value for each adapter ? thank you |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Read MTU value for each adapter "Heinz" <no@xxxxxx> wrote in message news:ej%23CjJ43JHA.5204@xxxxxx Quote: > Helllo, > > I have script that reads information for each network adapter. > > To make the script run, I need to add "on error resume next"... I don't > feel comfortable doing this, but otherwise it doesnt work at all. > > But my question is the following: > How could I read the MTU value for a network adapter? > There exists a .MTU property ( > http://msdn.microsoft.com/en-us/libr...17(VS.85).aspx ) - but I get > no value for this. > > Here is the code: > > on Error Resume Next '** without this, the script crashes .... > > Const wbemFlagReturnImmediately = &h10 > Const wbemFlagForwardOnly = &h20 > > strComputer = "." > > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") > Set colItems = objWMIService.ExecQuery("SELECT * FROM > Win32_NetworkAdapterConfiguration", "WQL", _ > wbemFlagReturnImmediately + wbemFlagForwardOnly) > > For Each objItem In colItems > WScript.Echo "Caption: " & objItem.Caption > WScript.Echo "IPEnabled: " & objItem.IPEnabled > > strDefaultIPGateway = Join(objItem.DefaultIPGateway, ",") > WScript.Echo "DefaultIPGateway: " & strDefaultIPGateway > > WScript.Echo "Description: " & objItem.Description > WScript.Echo "DHCPEnabled: " & objItem.DHCPEnabled > WScript.Echo "DHCPServer: " & objItem.DHCPServer > > WScript.Echo "DNSDomain: " & objItem.DNSDomain > WScript.Echo "DNSHostName: " & objItem.DNSHostName > > strDNSServerSearchOrder = Join(objItem.DNSServerSearchOrder, ",") > WScript.Echo "DNSServerSearchOrder: " & strDNSServerSearchOrder > > WScript.Echo "Index: " & objItem.Index > > strIPAddress = Join(objItem.IPAddress, ",") > WScript.Echo "IPAddress: " & strIPAddress > > strIPSubnet = Join(objItem.IPSubnet, ",") > WScript.Echo "IPSubnet: " & strIPSubnet > > WScript.Echo "MTU: " & objItem.MTU '** always empty... > > WScript.Echo "*************" > Next > > > Any idea how I could read the MTU value for each adapter ? > > > thank you network adapter uses or returns it. Did you check by different means (e.g. via the Control Panel) that your adapter is aware of this property? Your uncomfortable feelings about the "On error" statement are justified. However, instead of suppressing the error messages, you should deal with them in a controlled manner. The messages occur when the adapter returns a null value, which you then try to convert from an array to a string, which generates an error. It would be much better to perform the conversion conditionally, as per the modified code below: [01] Const wbemFlagReturnImmediately = &h10 [02] Const wbemFlagForwardOnly = &h20 [03] [04] strComputer = "." [05] [06] Set objWMIService = GetObject("winmgmts:\\" _ [07] & strComputer & "\root\CIMV2") [08] Set colItems = objWMIService.ExecQuery("SELECT * " _ [09] & "FROM Win32_NetworkAdapterConfiguration", _ [10] "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly) [11] [12] For Each objItem In colItems [13] WScript.Echo "Caption: " & objItem.Caption [14] WScript.Echo "IPEnabled: " & objItem.IPEnabled [15] WScript.Echo "DefaultIPGateway: " & ToString(objItem.DefaultIPGateway) [16] WScript.Echo "Description: " & objItem.Description [17] WScript.Echo "DHCPEnabled: " & objItem.DHCPEnabled [18] WScript.Echo "DHCPServer: " & objItem.DHCPServer [19] WScript.Echo "DNSDomain: " & objItem.DNSDomain [20] WScript.Echo "DNSHostName: " & objItem.DNSHostName [21] WScript.Echo "DNSServerSearchOrder: " & ToString(objItem.DNSServerSearchOrder) [22] WScript.Echo "Index: " & objItem.Index [23] WScript.Echo "IPAddress: " & ToString(objItem.ipaddress) [24] WScript.Echo "IPSubnet: " & ToString(objItem.IPSubnet) [25] WScript.Echo "MTU: " & objItem.MTU [26] WScript.Echo "*************" [27] Next [28] [29] '--------------------------- [30] 'Turn an array into a string [31] '--------------------------- [32] Function ToString (value) [33] If IsArray(value) Then [34] ToString = Join(value, ",") [35] Else [36] ToString = value [37] End If [38] End Function |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| 6T04 Adapter, Isatap, Microsoft Isatap Adapter (!) | Vista performance & maintenance | |||
| Read messages turn UN-read again | Live Mail | |||
| Bridging all traffic from physical adapter to virtual adapter | Virtual Server | |||
| READ THIS IF YOU CANNOT GET DRIVE TO READ DISK TO FIX VISTA ERROR! | Vista hardware & devices | |||
| Folders/files read only/can't create new folder in read only folde | Vista account administration | |||