Enable method of the Win32_NetworkAdapter Class

Expand
1 out of 5 rated this helpful - Rate this topic

Enable method of the Win32_NetworkAdapter Class

Applies to: desktop apps only

The Enable method enables the network adapter.

Syntax

uint32 Enable();

Parameters

This method has no parameters.

Return value

Returns zero (0) to indicate success. Any other number indicates an error. For error codes, see WMI Error Constants or WbemErrorEnum.

Examples

For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository.

For C++ code examples, see WMI C++ Application Examples.

The following Visual Basic Script example enables the first network adapter and shows the status of the NetEnabled property. For more information, see SWbemObjectSet.ItemIndex.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & _
    strComputer & "\root\cimv2")

set colAdapters = _
    objWMIService.Execquery_
        ("Select * from Win32_NetworkAdapter Where NetEnabled=True")
For Each Adapter in colAdapters
    WScript.Echo Adapter.DeviceId & "    " & Adapter.Name
Next
errReturn = colAdapters.ItemIndex(0).Enable()
If errReturn <> 0 Then
    WScript.Echo "Enable Network adapter failed for adapter= "_
        & colAdapters.ItemIndex(0).DeviceId
Else 
    WScript.Echo "Enable Network adapter succeeded for adapter= "_
        & colAdapters.ItemIndex(0).DeviceId 
End If 
WScript.Echo "NetEnabled= " & colAdapters.ItemIndex(0).NetEnabled

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008

Namespace

\root\CIMV2

MOF

Cimwin32.mof

DLL

Cimwin32.dll

See also

Win32_NetworkAdapter

 

 

Send comments about this topic to Microsoft

Build date: 3/9/2012

Did you find this helpful?
(1500 characters remaining)
Community Additions ADD
Doesn't seem to be supported on Windows 7

<p>I tried C# and Visual Basic example for enabling and disabling a network card by using WMI. Other than enabling/disabling NICs, all seem to work.<br />The document on this should be more detailed.</p>

<p>Correction : I made it work using C#. The point is that whether you have access privilege as administrator.</p>

5/29/2012
NetEnabled value in the sample is wrong
The query is invalid - it selects already enabled NICs. Correct query should be -
("Select * from Win32_NetworkAdapter Where NetEnabled=False")
It also make sense to select physical cards with the clause
PhysicalAdapter=true
3/3/2011
Enable and Disable method are not supported under win xp
NetEnabled -> not supported under windows xp
ItemIndex -> not supported under windows xp

Enable -> not supported under windows xp
Disable ->  not supported under windows xp

So how to enable/disable NIC interfaces under windows XP (with static ipaddress, so no DHCP)?
7/26/2010