The Enable method enables the network adapter.
Syntax
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 |
| MOF | Cimwin32.mof |
| DLL | Cimwin32.dll |
| Namespace | \root\cimv2 |
See Also
- Win32_NetworkAdapter
Send comments about this topic to Microsoft
Build date: 1/8/2010
Build type: MSDN