Click to Rate and Give Feedback
MSDN
MSDN Library
WMI Reference
WMI Classes
Win32 Classes
 Enable Method of the Win32_NetworkA...
Enable Method of the Win32_NetworkAdapter Class

The Enable method enables the network adapter.

Syntax

MOF
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 clientWindows Vista
Minimum supported serverWindows Server 2008
MOFCimwin32.mof
DLLCimwin32.dll
Namespace\root\cimv2

See Also

Win32_NetworkAdapter

 

 

Send comments about this topic to Microsoft

Build date: 1/8/2010

Build type: MSDN

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker