Trying to use WMI to display the MTU values for the network adapters on a system

StackOverflow https://stackoverflow.com/questions/12483760

  •  02-07-2021
  •  | 
  •  

سؤال

I have this subroutine that is just displaying blank lines.

'*************************************************************************
' Check MTU
'*************************************************************************
Sub CheckMTU()
   WScript.Echo("Check if MTU Size is set to 1300")
   WScript.Echo("------------------------------------")
   Set colNetwork = objWMISrvc.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
   For Each objItem in colNetwork
      WScript.Echo(objItem.MTU & vbCrLf)
   Next
End Sub

I want to test to see if the network adapters have a MTU value of 1300. This will be run on multiple machines and the issue I have is the name of network adapters in the registry are always different. It would be nice if my implementation worked...

Any ideas?

EDIT: I changed the subroutine to this, but it isn't working.

'*************************************************************************
' Check MTU
'*************************************************************************
Sub CheckMTU()
   Dim intResult
   WScript.Echo("Verify MTU Size is 1300. Changes MTU Size to 1300 ")
   WScript.Echo("------------------------------------")
   Set colNetwork = objWMISrvc.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE IPEnabled = True") 'WHERE IPEnabled = True
   For Each objItem in colNetwork
      WScript.Echo objItem
      intResult = objItem.SetMTU(1300)
      WScript.Echo intResult
   Next
   If intResult = 0 or intResult = 1 Then
      WScript.Echo("Network Adapter MTU Value is set to 1300. Test PASSED" & vbCrLf)
   Else
      WScript.Echo("Network Adapter MTU Value can't be set to 1300. Test FAILED" & vbCrLf)
   End If
End Sub

It isn't even printing out the intResult or objItem. It almost feels as if it isn't getting anything from colNetwork.

Any suggestions? Should I make a new post?

هل كانت مفيدة؟

المحلول

Not 100% sure why there's no MTU value.. BUT you can always set the MTU value calling the SetMTU method: http://msdn.microsoft.com/en-us/library/windows/desktop/aa393463(v=vs.85).aspx

نصائح أخرى

Change:

WScript.Echo(objItem.MTU & vbCrLf)

To:

WScript.Echo objItem.MTU

I think is because this value is used to overwrite the default value.

"Overrides the default Maximum Transmission Unit (MTU) for a network interface."

If it's null, the default value is used, if it's not, it overwrites the default value. You can view the default MTU value reported by the driver with the following netsh command:

netsh interface ip show subinterfaces
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top