Export (0) Print
Expand All

EnableStatic method of the Win32_NetworkAdapterConfiguration class

The EnableStatic WMI class method enables static TCP/IP addressing for the target network adapter. As a result, DHCP for this network adapter is disabled.

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

Syntax


uint32 EnableStatic(
  [in]  string IPAddress[],
  [in]  string SubnetMask[]
);

Parameters

IPAddress [in]

Lists all of the static IP addresses for the current network adapter.

Example: 155.34.22.0.

SubnetMask [in]

Subnet masks that complement the values in the IPAddress parameter.

Example: 255.255.0.0.

Return value

Return codeDescription
0

Successful completion, no reboot required.

1

Successful completion, reboot required.

64

Method not supported on this platform.

65

Unknown failure.

66

Invalid subnet mask.

67

An error occurred while processing an instance that was returned.

68

Invalid input parameter.

69

More than five gateways specified.

70

Invalid IP address.

71

Invalid gateway IP address.

72

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

73

Invalid domain name.

74

Invalid host name.

75

No primary or secondary WINS server defined.

76

Invalid file.

77

Invalid system path.

78

File copy failed.

79

Invalid security parameter.

80

Unable to configure TCP/IP service.

81

Unable to configure DHCP service. For more information, see the Remarks section.

82

Unable to renew DHCP lease.

83

Unable to release DHCP lease.

84

IP not enabled on adapter.

85

IPX not enabled on adapter.

86

Frame or network number bounds error.

87

Invalid frame type.

88

Invalid network number.

89

Duplicate network number.

90

Parameter out of bounds.

91

Access denied.

92

Out of memory.

93

Already exists.

94

Path, file, or object not found.

95

Unable to notify service.

96

Unable to notify DNS service.

97

Interface not configurable.

98

Not all DHCP leases could be released or renewed.

100

DHCP not enabled on adapter.

2147786788

Write lock not enabled. For more information, see INetCfgLock::AcquireWriteLock.

 

Remarks

When using EnableStatic to change the IP address of the remote computer, while being connected through that adapter, you will likely loose connection to the remote computer, and receive an RPC not available error-message. (the settings are changed however). To avoid this scenario, consider changing the Gateway and/or DNS-settings prior to setting the adapter's IP-address.

When using EnableStatic to give an adapter a static IP configuration, the function returns an "81 - Unable to configure DHCP service" if the adapter is already configured with a static address. However, the function still succeeds in setting with the new operation.

Examples

The Static IP and then join to a domain PowerShell code sample, on TechNet Gallery, uses EnableStatic to add a static IP to a local machine.

The Assign a Static IP Address VBScript code example, on TechNet Gallery, uses EnableStatic to set the IP address of a computer.

The following VBScript sample demonstrates how to disable 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  This script only applies to NT-based systems Change the ipaddr and subnet variables below to the values you wish to apply to the adapter.

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

ipaddr = Array("1.1.1.1")
subnet = Array("255.255.255.0")


RetVal = Adapter.EnableStatic(ipaddr,subnet)

if RetVal = 0 then 
 WScript.Echo "DHCP disabled, using static IP address"
else 
 WScript.Echo "DHCP disable failed"
end if

The following Perl sample demonstrates how to disable 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  This script only applies to NT-based systems Change the ipaddr and subnet variables below to the values you wish to apply to the adapter.

use strict;
use Win32::OLE;

my ($Adapter, @ipaddr, @subnet, $RetVal);  
eval { $Adapter = 
 Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2:Win32_NetworkAdapterConfiguration.Index=\"0\""); };

unless ($@) 
{
 push @ipaddr, "192.168.144.107";
 push @subnet, "255.255.255.0";

 $RetVal = $Adapter->EnableStatic(\@ipaddr, \@subnet);

 if ($RetVal == 0) 
 {
  print "\nDHCP disabled, using static IP address\n";
 }
 else 
 {
  print "\nDHCP disable failed\n";
 }
}
else
{
 print STDERR "\n", Win32::OLE->LastError, "\n";
}

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003

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

 

 

Show:
© 2015 Microsoft