EnableDHCP method of the Win32_NetworkAdapterConfiguration class

The EnableDHCP WMI class method enables the Dynamic Host Configuration Protocol (DHCP) for service with this network adapter. DHCP allows IP addresses to be dynamically allocated.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax

uint32 EnableDHCP();

Parameters

This method has no parameters.

Return value

Returns a value of 0 (zero) for a successful completion when a reboot is not required, 1 (one) for a successful completion when a reboot is required, and any other number if there is an error. For more information on error codes, see WMI Error Constants or WbemErrorEnum. For general HRESULT values, see System Error Codes.

Successful completion, no reboot required

0

Successful completion, no reboot required.

Successful completion, reboot required

1

Successful completion, reboot required.

Method not supported on this platform

64

Method not supported on this platform.

Unknown failure

65

Unknown failure.

Invalid subnet mask

66

Invalid subnet mask.

An error occurred while processing an Instance that was returned

67

An error occurred while processing an instance that was returned.

Invalid input parameter

68

Invalid input parameter.

More than 5 gateways specified

69

More than five gateways specified.

Invalid IP address

70

Invalid IP address.

Invalid gateway IP address

71

Invalid gateway IP address.

An error occurred while accessing the Registry for the requested information

72

An error occurred while accessing the registry for the requested information.

Invalid domain name

73

Invalid domain name.

Invalid host name

74

Invalid host name.

No primary/secondary WINS server defined

75

No primary or secondary WINS server defined.

Invalid file

76

Invalid file.

Invalid system path

77

Invalid system path.

File copy failed

78

File copy failed.

Invalid security parameter

79

Invalid security parameter.

Unable to configure TCP/IP service

80

Unable to configure TCP/IP service.

Unable to configure DHCP service

81

Unable to configure DHCP service.

Unable to renew DHCP lease

82

Unable to renew DHCP lease.

Unable to release DHCP lease

83

Unable to release DHCP lease.

IP not enabled on adapter

84

IP not enabled on adapter.

IPX not enabled on adapter

85

IPX not enabled on adapter.

Frame/network number bounds error

86

Frame or network number bounds error.

Invalid frame type

87

Invalid frame type.

Invalid network number

88

Invalid network number.

Duplicate network number

89

Duplicate network number.

Parameter out of bounds

90

Parameter out of bounds.

Access denied

91

Access denied.

Out of memory

92

Out of memory.

Already exists

93

Already exists.

Path, file or object not found

94

Path, file, or object not found.

Unable to notify service

95

Unable to notify service.

Unable to notify DNS service

96

Unable to notify DNS service.

Interface not configurable

97

Interface not configurable.

Not all DHCP leases could be released/renewed

98

Not all DHCP leases could be released or renewed.

DHCP not enabled on adapter

100

DHCP not enabled on the adapter.

Other

101 4294967295

Remarks

This method does not clears any static default gateways present on the machine.

Examples

The following VBScript code sample demonstrates how to enable DHCP use on an instance of Win32_NetworkAdapterConfiguration . In this case we specify the adapter with an Index of 0. The correct index should be selected from Win32_NetworkAdapter instances for other interfaces.

Note

Supported on NT platforms only.

Set Adapter = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=0")

RetVal = Adapter.EnableDHCP()

if RetVal = 0 then 
 WScript.Echo "DHCP Enabled"
else 
 WScript.Echo "DHCP enable failed"
end if

The following Perl code sample demonstrates how to enable DHCP use on an instance of Win32_NetworkAdapterConfiguration . In this case we specify the adapter with an Index of 0. The correct index should be selected from Win32_NetworkAdapter instances for other interfaces.

Note

Supported on NT platforms only.

use strict;
use Win32::OLE;

my ( $Adapter, $RetVal );

eval { $Adapter = Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2")->
       Get("Win32_NetworkAdapterConfiguration=0"); };
unless ($@)
{
 print "\n";
 $RetVal = $Adapter->EnableDHCP();
 if ( $RetVal == 0)
 {
  print "DHCP Enabled\n";
 }
 else
 {
  print "DHCP enable failed\n";
 }
}
else
{
 print STDERR Win32::OLE->LastError, "\n";
}

Requirements

Requirement Value
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Namespace
Root\CIMV2
MOF
CIMWin32.mof
DLL
CIMWin32.dll

See also

Computer System Hardware Classes

Win32_NetworkAdapterConfiguration

WMI Tasks: Networking

WMI Tasks: Accounts and Domains

IPv6 and IPv4 Support in WMI