none
SetIPConnectionMetric() on Server 2008 R2

    Question

  • Hi,

    SetIPConnectionMetric method of the Win32_NetworkAdapterConfiguration Class,  used to set the routing metric associated with a  IP-bound adapter, works on Server 2003, but does not seem to work on 64 bit Windows, and specifically on Server 2008 R2.

    Any idea why this happens and a workaround / solution , if possible?

    Regards,
    CD


    Friday, June 08, 2012 10:41 AM

Answers

  • Ok - I just tested on WS2003 and XP and all updated but took a little bit to show that they were updated.

    Here is the code that worked:

    $adpt=gwmi -q "Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True"
    $adpt.IPConnectionMetric
    $metric=$adpt.IPConnectionMetric
    $adpt.SetIPConnectionMetric($metric+100)
    Write-Host 'Before reset - ' + $adpt.IPConnectionMetric -fore green
    $adpt=gwmi -q "Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True"
    Write-Host 'After reset - ' + $adpt.IPConnectionMetric  -fore black -back white

    If you do not reaquire the adapter it will never look like it is changed.

    Actually I went back to WIn 7 and I can reproduce you issue.  The Metric will only set after a reboot on Win7. I suspect that may be also true on WS2008R2.

    I suspect this may have been done to prevent wireless conenctions from stealing hte machine by  dynamically changing the metric.  Or ... it could just be a bug.

    (This behaves the same on both 32 and 64 bit versions.)


    ¯\_(ツ)_/¯



    Friday, June 08, 2012 7:13 PM

All replies

  • Hi,

    When you say that something didn't work, you have to say how it didn't work.

    Bill

    Friday, June 08, 2012 4:03 PM
    Moderator
  • MSDN documentation says : The SetIPConnectionMetric method is used to set the routing metric associated with this IP-bound adapter.

    On Server 2003: When SetIPConnectionMetric( IPConnectionMetric ) is called, it returns 0 (Successful completion, no reboot required) and the routing metric on the relevant adapter is changed to IPConnectionMetric .

    On Server 2008 R2: When SetIPConnectionMetric( IPConnectionMetric ) is called, it returns 0 (Successful completion, no reboot required) but the routing metric on the relevant adapter remains unchanged . Logged in as Administrator when running the script which calls SetIPConnectionMetric().

    I hope this is of help.

    Regards,

    CD


    Friday, June 08, 2012 4:26 PM
  • MSDN documentation says : The SetIPConnectionMetric method is used to set the routing metric associated with this IP-bound adapter.

    On Server 2003: When SetIPConnectionMetric( IPConnectionMetric ) is called, it returns 0 (Successful completion, no reboot required) and the routing metric on the relevant adapter is changed to IPConnectionMetric .

    On Server 2008 R2: When SetIPConnectionMetric( IPConnectionMetric ) is called, it returns 0 (Successful completion, no reboot required) but the routing metric on the relevant adapter remains unchanged . Logged in as Administrator when running the script which calls SetIPConnectionMetric().

    I hope this is of help.

    Regards,

    CD


    Run elevated.  Use PowerShell. 

    $adapt=gwmi Win32_NetworkAdapterConfiguration -Filter 'Index=8' -EnableAllPrivileges

    See Siddaway - http://itknowledgeexchange.techtarget.com/powershell/changing-ip-connection-metric/

    Be sure to reboot.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, June 08, 2012 4:58 PM
    Friday, June 08, 2012 4:31 PM
  • Thanks for the input, but I do not wish to reboot (or rather am not in a position to) the system, and in any case, rebooting was not required on Server 2003.

    My script is essentially a modification of the script presented on http://gallery.technet.microsoft.com/scriptcenter/73367c75-7a39-44dc-a8d7-eb2359030969

    Thanks.

    Friday, June 08, 2012 5:15 PM
  • Hi,

    Are you running the script from a elevated command prompt window? (Right-click, Run as administrator.) It is not sufficient that your account is just a member of the local Administrators group. With UAC enabled, you must elevate for full admin privileges.

    Bill


    Friday, June 08, 2012 5:53 PM
    Moderator
  • Thanks for the input, but I do not wish to reboot (or rather am not in a position to) the system, and in any case, rebooting was not required on Server 2003.

    My script is essentially a modification of the script presented on http://gallery.technet.microsoft.com/scriptcenter/73367c75-7a39-44dc-a8d7-eb2359030969

    Thanks.

    Yes - you may have to go back to WS2003 to get this fixed.  Of course you can follow Bill's suggestion.

    Sidaway is usually pretty close on most of his items.

     I tested on a WS2008R2 server but got kicked off before I could finish.  Maybe tomorrow when everybody is gone.  Gotta upgrade my 2003 test server soon.


    ¯\_(ツ)_/¯

    Friday, June 08, 2012 7:02 PM
  • Ok - I just tested on WS2003 and XP and all updated but took a little bit to show that they were updated.

    Here is the code that worked:

    $adpt=gwmi -q "Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True"
    $adpt.IPConnectionMetric
    $metric=$adpt.IPConnectionMetric
    $adpt.SetIPConnectionMetric($metric+100)
    Write-Host 'Before reset - ' + $adpt.IPConnectionMetric -fore green
    $adpt=gwmi -q "Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True"
    Write-Host 'After reset - ' + $adpt.IPConnectionMetric  -fore black -back white

    If you do not reaquire the adapter it will never look like it is changed.

    Actually I went back to WIn 7 and I can reproduce you issue.  The Metric will only set after a reboot on Win7. I suspect that may be also true on WS2008R2.

    I suspect this may have been done to prevent wireless conenctions from stealing hte machine by  dynamically changing the metric.  Or ... it could just be a bug.

    (This behaves the same on both 32 and 64 bit versions.)


    ¯\_(ツ)_/¯



    Friday, June 08, 2012 7:13 PM
  • I suspect this may have been done to prevent wireless conenctions from stealing hte machine by  dynamically changing the metric.  Or ... it could just be a bug.

    Thanks, jrv. Any way we can find out which one it is (i.e. if the behaviour I see in WS2008R2 is actually intended ot it is a bug).

    Monday, June 11, 2012 10:46 AM
  • Call MS support.  Log an online support issue.  Post in the Server forum fro WS2008R2.  One or all of those might get you a finding or:

    Post a bug report on http://connect.microsoft.com


    ¯\_(ツ)_/¯

    Monday, June 11, 2012 2:59 PM