none
[Q] SetGateways of Win32_NetworkAdaperConfiguration WMI Class

    Pregunta

  • Hello,

    In the following code, SetGateways() method clears the previous gateway setting in ohter Windows than Vista. In Vista, the previous gateway setting is never cleared by this VB script. Is this a bug? FYI, I have executed it in the elevated cmd prompt.
    Thanks in advance.

    =====

    strComputer = "."
    strSettingID = WScript.Arguments(0)
    strIpAddr = WScript.Arguments(1)
    Set objWMIService = GetObject( _
        "winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNetAdapters = objWMIService.ExecQuery _
        ("Select * from Win32_NetworkAdapterConfiguration " _
            & "where IPEnabled=TRUE")
    strIPAddress = Array(strIpAddr)
    strSubnetMask = Array("255.255.255.0")
    strGateway = Array()
    strDNS = Null
     
    For Each objNetAdapter in colNetAdapters
        If objNetAdapter.SettingID = strSettingID Then
            errEnable = objNetAdapter.EnableStatic( _
                strIPAddress, strSubnetMask)
            errDNS = objNetAdapter.SetDNSServerSearchOrder(_
                strDNS)
            errGateways = objNetAdapter.SetGateways( _
                strGateway)
        End If
    Next
    martes, 23 de octubre de 2007 13:56

Respuestas

  • If you want to try to escalate this issue then you should contact me as a partner and I can happily create a case for you, otherwise you can contact main support and go that direction. MSDN isn't an escalation path :-)

    viernes, 26 de octubre de 2007 17:48

Todas las respuestas

  •  

    Any failures detected in the code? Does it simply not work?
    martes, 23 de octubre de 2007 17:59
  • Hello, Burce N. Baker

    strGateway = Array()
    objNetAdapter.SetGateways(strGateway)

    On 2K/XP/2K3 machine, this statements clear the previous gateway setting if there is. For example, before running this script, assuming default gateway setting is 192.168.2.1, this default gateway setting is cleared to blank after running the script.

    But on Vista, running this script doesnot change the previous gateway setting at all. After running this script, the previous gateway setting(192.168.2.1) is still in there.


    Regards,
    SJLEE
    martes, 23 de octubre de 2007 18:35
  •  

    To recheck, the setgateways call return no error?
    martes, 23 de octubre de 2007 19:15
  • It returns 0(no error).
    Please test it with 2 script files in Vista and other Windows: (These script files will change IP settings on all eanbled network adapters, so, PLEASE ENABLE ONLY I NETWORK ADAPTER for your test!)
    ====================================
    strComputer = "."
    Set objWMIService = GetObject( _
        "winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNetAdapters = objWMIService.ExecQuery _
        ("Select * from Win32_NetworkAdapterConfiguration " _
            & "where IPEnabled=TRUE")
    strIPAddress = Array("192.168.0.2")
    strSubnetMask = Array("255.255.255.0")
    strGateway = Array()
    strDNS = Null
     
    For Each objNetAdapter in colNetAdapters
        errEnable = objNetAdapter.EnableStatic( _
            strIPAddress, strSubnetMask)
        errDNS = objNetAdapter.SetDNSServerSearchOrder(_
            strDNS)
        errGateways = objNetAdapter.SetGateways( _
            strGateway)

        WScript.Echo "errGateways:" & errGateways
    Next
    =====================================
    strComputer = "."
    Set objWMIService = GetObject( _
        "winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNetAdapters = objWMIService.ExecQuery _
        ("Select * from Win32_NetworkAdapterConfiguration " _
            & "where IPEnabled=TRUE")
    strIPAddress = Array("192.168.0.2")
    strSubnetMask = Array("255.255.255.0")
    strGateway = Array("192.168.0.1")
    strGatewayMetric = Array(1)
    strDNS = Array("192.168.0.1")
     
    For Each objNetAdapter in colNetAdapters
        errEnable = objNetAdapter.EnableStatic( _
            strIPAddress, strSubnetMask)
        errGateways = objNetAdapter.SetGateways( _
            strGateway, strGatewaymetric)
        errDNS = objNetAdapter.SetDNSServerSearchOrder(_
            strDNS)

        WScript.Echo "errGateways:" & errGateways
    Next
    martes, 23 de octubre de 2007 20:16
  • Apparently the action if strGateway is unknown if it is empty because it usually has a list of IP Addresses, in otherwords, the people I talked to didn't know the section of code that would handle if that array was empty therefore were unsure of what would happen.

     

    DefaultIPGateway

    List of IP addresses to gateways where network packets are routed.

     

    http://msdn2.microsoft.com/en-us/library/aa393301.aspx
    miércoles, 24 de octubre de 2007 20:52
  • This is the method to clear the previous gateway setting and works well on other Windows(2K, XP, 2K3).

    If you have any workaround or substitute, please let me know.

    Thanks in advance.

    jueves, 25 de octubre de 2007 8:11
  • This is clearly not stated in the documentation that sending in a empty array should function like that and is not a supported functionality in Vista.  I expect any hidden functionality was modified when that section of code was re-organized for Vista.

     

    How about filling it with with values to explictly clear it (or reset it as the case may be).

     

    jueves, 25 de octubre de 2007 18:13
  • How about filling it with with values to explictly clear it (or reset it as the case may be).

    ===

    Please tell me the method.

     

    I need MS verification of this problem. I think it is a very critical bug.

     

    viernes, 26 de octubre de 2007 12:16
  • If you want to try to escalate this issue then you should contact me as a partner and I can happily create a case for you, otherwise you can contact main support and go that direction. MSDN isn't an escalation path :-)

    viernes, 26 de octubre de 2007 17:48
  • Hi, again.

     

    How to escalate this issue to be verified?

    FYI, I have at least 4 credits (for purchase of VS) to be technically supported by MS support team.

    Thanks.

    lunes, 29 de octubre de 2007 13:08
  • Simply contact me at Microsoft with your partner ID and I can get the process started.

    lunes, 29 de octubre de 2007 17:05
  • After some more tests, I am sure that the problem be an actual bug.

    I will request technical support in local MS office to report this bug.

     

    Please test the problem more like this: (Just try these steps in "Manage network connections".)

    1. If there are 2 network adapters, set their IPs with a value with gateway setting, respectively.

    2. As you remove the gateway setting, please check if internet will be connected.

     

    You may watch some weired symptoms.

     

    3. The method to clear the syptoms that I found is to disable both adapters and reenable them again.

     

    Thanks.
    lunes, 29 de octubre de 2007 17:11
  • Dear Bruce N. Baker
     
    I have sent a mail to you. Please check my mail.
    Thanks.

    lunes, 29 de octubre de 2007 17:34
  •  

    No matching issue found in database. Do you have any issue on aother box? Are all the drivers update properly?
    lunes, 29 de octubre de 2007 18:17
  • Dear Bruce N. Baker

     

    I'm having exactly the same problem.
    So could you tell me how to fix or avoid this problem?
    Thanks for your help.

     

    Schroeder Chung
    jueves, 06 de marzo de 2008 3:03
  • Hi there,

    I have exactly the same problem. It just seems not to be possible to remove the gateway in Vista using SetGateways. It's working fine with XP and 2000, though.

    Did someone find a solution in the meantime?
    miércoles, 01 de octubre de 2008 1:42
  • Any solution for this ? I have the same problem here!!
    lunes, 13 de abril de 2009 21:13
  • I've tried to set the gateway address as same as the address of the NIC itself.

    Then the default gateway setting has been cleared.

     

    With Windows7, Delphi2007

    miércoles, 17 de agosto de 2011 19:47