No respond in EnableStatic using WMI RRS feed

  • Question

  • Hello I have been 2 days to figure out this problem so i decided to ask. when I change the gateway it was success i was only took 3 seconds to return the value of "0" according to EnableStatic return value "0 Successful completion, no reboot required", but when i change the IPAddress it was hang for too long or it did not respond anymore and I wait for 10 to 20 minutes before it response the return value is "The remote procedure call failed. (Exception from HRESULT: 0x800706BE), if not then I will terminate it using task manager. but on the remote computer it was changed the IPAddress successfully. 

    is there any vb.net code to return the value with success using wmi? I tried it both on windows xp and windows 7 but the same result.

    here is my code:

    Public Function ChangeIP()
            Dim result As Boolean
            Dim MyConOptions As New System.Management.ConnectionOptions
            Dim SystemName As String = "computername"
                With MyConOptions
                    .Impersonation = System.Management.ImpersonationLevel.Impersonate
                    .Authentication = System.Management.AuthenticationLevel.PacketPrivacy
                    If txtUsername.Text <> "" Then
                        .Username = "testuser"
                        .Password = "testpass"
                    End If
                    .Authority = "NTLMDOMAIN:" & SystemName
                End With
                Dim MyMgtScope As System.Management.ManagementScope
                MyMgtScope = New System.Management.ManagementScope("\\" & SystemName & "\root\cimv2", MyConOptions)
                If MyMgtScope.IsConnected = True Then
                    Dim MyObjSearcher As System.Management.ManagementObjectSearcher
                    Dim MyColl As System.Management.ManagementObjectCollection
                    Dim MyObj As System.Management.ManagementObject
                    Dim query As ObjectQuery
                    query = New ObjectQuery("Select * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
                    Dim searcher As ManagementObjectSearcher
                    searcher = New ManagementObjectSearcher(MyMgtScope, query)
                    MyColl = searcher.Get()
                    For Each MyObj In MyColl
                        If Not CBool(MyObj("IPEnabled")) Then
                            Continue For
                        End If
                        Dim objectNewIP As ManagementBaseObject = Nothing
                        Dim objectSetIP As ManagementBaseObject = Nothing
                        objectNewIP = MyObj.GetMethodParameters("EnableStatic")
                        objectNewIP("SubnetMask") = New String() {txtSubnetMask.Text}
                        objectNewIP("IPAddress") = New String() {txtIPAddress.Text}
                            objectSetIP = MyObj.InvokeMethod("EnableStatic", objectNewIP, Nothing)
                        Catch ex As Exception
                            Dim result1 As Integer = CType(objectSetIP("returnValue"), Integer)
                            If result1 = "The remote procedure call failed. (Exception from HRESULT: 0x800706BE)" Then
                                Exit For
                            End If
                        End Try
                    result = True
                    MyObjSearcher = Nothing
                    MyColl = Nothing
                ElseIf MyMgtScope.IsConnected = False Then
                    Return False
                    Exit Function
                End If
            Catch ex As Exception
            End Try
            Return result
        End Function

    • Edited by Vhadz Monday, February 15, 2016 5:22 AM
    • Moved by Bill_Stewart Monday, March 14, 2016 6:36 PM User does not understand scope of "question"
    Monday, February 15, 2016 5:19 AM

All replies

  • You are posting in the wrong forum. This is not a VB.Net forum.

    If you change the remote address the call will always fail because the change takes effect immediately.  YOU are no longer connected to the old address.  There is not way around this.

    Using static addresses is obsolete for almost all workstations and servers.  Use a DHCP address lease that is assigned to the adapter by MAC address or use a lease that never expires.


    Monday, February 15, 2016 5:33 AM
  • thank you for the fast response. ans sorry about posting vb.net. When I change IPAddress I am using hostname not ip address.  is there any vb.net code to return the value as fast as posible and no need to response from the client?

    I tried threading like this

    Private Sub Change_IP()
            Dim ChangeIPthread As System.Threading.Thread
            ChangeIPthread = New System.Threading.Thread(AddressOf ChangeIP)

    but when I exit my application it was hang.

    Monday, February 15, 2016 5:47 AM
  • Can't be done.  The host name will point wrong until you flush the local cache or until it times out.  The DNS server will not be updated for anywhere from 30 seconds to many  minutes.

    If you think about it you will realize why it cannot be made to work.

    Do not use static addresses. It is almost never necessary.


    Monday, February 15, 2016 5:58 AM