Discussion:
Set Static IP configuration, Enable/Disable DHCP
(too old to reply)
G***@web.de
2007-03-29 20:12:36 UTC
Permalink
Hi,
I have a problem finding the appropriate information on how to set a
static IP configuration (IP address, Subnet Mask, DNS, WINS, Gateway)
and enable/disable DHCP on a given adapter. I can get an enumeration
of all available network adapter and their current configuration using
the IP Helper API, but how can I programmatically (from C++) set a new
static IP configuration or switch between static and DHCP settings for
an adapter. The IP Helper API provides a function to add an IP
Address, but this is not helpful in that case because this would leave
the current (old) configuration untouched. Besides this would not
allow switching between static and DHCP settings. There's a function
DeleteIPAddress as well in the IP Helper API but for this I need the
NTEContext of the IP address which I don't have in the program,
because I didn't add this one with AddIpAddress and couldn't find any
method to retrieve a context for a present IP. Even if I could do this
there's the same problem switching to DHCP and back to static
configuration.
Regards,
Gunnar
Arkady Frenkel
2007-03-30 07:39:53 UTC
Permalink
You need to use wmi interfaces.
Look at EnableDHCP()/EnableStatic() of the Win32_NetworkAdapterConfiguration
Class
Arkady
Post by G***@web.de
Hi,
I have a problem finding the appropriate information on how to set a
static IP configuration (IP address, Subnet Mask, DNS, WINS, Gateway)
and enable/disable DHCP on a given adapter. I can get an enumeration
of all available network adapter and their current configuration using
the IP Helper API, but how can I programmatically (from C++) set a new
static IP configuration or switch between static and DHCP settings for
an adapter. The IP Helper API provides a function to add an IP
Address, but this is not helpful in that case because this would leave
the current (old) configuration untouched. Besides this would not
allow switching between static and DHCP settings. There's a function
DeleteIPAddress as well in the IP Helper API but for this I need the
NTEContext of the IP address which I don't have in the program,
because I didn't add this one with AddIpAddress and couldn't find any
method to retrieve a context for a present IP. Even if I could do this
there's the same problem switching to DHCP and back to static
configuration.
Regards,
Gunnar
G***@web.de
2007-04-01 16:53:53 UTC
Permalink
I found some examples on how to enable DHCP on an adapter, but none of
these worked. The problem seem to be in this step:

IWbemClassObject* pInClass = NULL;
hr = pClass->GetMethod(L"EnableDHCP", 0, &pInClass, NULL);

This call returns WBEM_S_NO_ERROR, but pInClass is always NULL and so
the next step:

hr = pInClass->SpawnInstance(0, &pInInst);

Fails due to pInClass is a NULL pointer. Unfortunately I found the
documentation in the msdn not very helpful, the only few examples at
all are in VB Script and nothing in C++.
Post by Arkady Frenkel
You need to use wmi interfaces.
Look at EnableDHCP()/EnableStatic() of the Win32_NetworkAdapterConfiguration
Class
Arkady
Arkady Frenkel
2007-04-02 05:59:57 UTC
Permalink
Check WMI C/C++ examples in DDK.
Arkady
Post by G***@web.de
I found some examples on how to enable DHCP on an adapter, but none of
IWbemClassObject* pInClass = NULL;
hr = pClass->GetMethod(L"EnableDHCP", 0, &pInClass, NULL);
This call returns WBEM_S_NO_ERROR, but pInClass is always NULL and so
hr = pInClass->SpawnInstance(0, &pInInst);
Fails due to pInClass is a NULL pointer. Unfortunately I found the
documentation in the msdn not very helpful, the only few examples at
all are in VB Script and nothing in C++.
Post by Arkady Frenkel
You need to use wmi interfaces.
Look at EnableDHCP()/EnableStatic() of the
Win32_NetworkAdapterConfiguration
Class
Arkady
Vinayak
2011-02-14 11:29:58 UTC
Permalink
You can set the static ip values in the registry and set EnableDhcp to 0 for your network card. This can easily be done by RegSetValueEx apis. Then you need to disable and then enable that network adapter for those values to be configured. You can use this link for that:

http://stackoverflow.com/questions/4967422/on-enabling-network-adpater-autoconfiguration-ip-address-getting-set
Post by G***@web.de
Hi,
I have a problem finding the appropriate information on how to set a
static IP configuration (IP address, Subnet Mask, DNS, WINS, Gateway)
and enable/disable DHCP on a given adapter. I can get an enumeration
of all available network adapter and their current configuration using
the IP Helper API, but how can I programmatically (from C++) set a new
static IP configuration or switch between static and DHCP settings for
an adapter. The IP Helper API provides a function to add an IP
Address, but this is not helpful in that case because this would leave
the current (old) configuration untouched. Besides this would not
allow switching between static and DHCP settings. There's a function
DeleteIPAddress as well in the IP Helper API but for this I need the
NTEContext of the IP address which I don't have in the program,
because I didn't add this one with AddIpAddress and couldn't find any
method to retrieve a context for a present IP. Even if I could do this
there's the same problem switching to DHCP and back to static
configuration.
Regards,
Gunnar
Post by Arkady Frenkel
You need to use wmi interfaces.
Look at EnableDHCP()/EnableStatic() of the Win32_NetworkAdapterConfiguration
Class
Arkady
Post by G***@web.de
I found some examples on how to enable DHCP on an adapter, but none of
IWbemClassObject* pInClass = NULL;
hr = pClass->GetMethod(L"EnableDHCP", 0, &pInClass, NULL);
This call returns WBEM_S_NO_ERROR, but pInClass is always NULL and so
hr = pInClass->SpawnInstance(0, &pInInst);
Fails due to pInClass is a NULL pointer. Unfortunately I found the
documentation in the msdn not very helpful, the only few examples at
all are in VB Script and nothing in C++.
Post by Arkady Frenkel
Check WMI C/C++ examples in DDK.
Arkady
Submitted via EggHeadCafe
Excel JSON Storing Data
http://www.eggheadcafe.com/tutorials/aspnet/233e58b3-72f4-4220-8d45-37c2c44e795e/excel-json-storing-data.aspx
Vinayak
2011-02-14 11:32:05 UTC
Permalink
Set those values in the registry for that network card using RegSetValueEx API. Also set EnableDhcp
to 0 (for static). Then you need to disable and enable that network card. You can use this link where i've posted the code for it:-

http://stackoverflow.com/questions/4967422/on-enabling-network-adpater-autoconfiguration-ip-address-getting-set
Post by G***@web.de
Hi,
I have a problem finding the appropriate information on how to set a
static IP configuration (IP address, Subnet Mask, DNS, WINS, Gateway)
and enable/disable DHCP on a given adapter. I can get an enumeration
of all available network adapter and their current configuration using
the IP Helper API, but how can I programmatically (from C++) set a new
static IP configuration or switch between static and DHCP settings for
an adapter. The IP Helper API provides a function to add an IP
Address, but this is not helpful in that case because this would leave
the current (old) configuration untouched. Besides this would not
allow switching between static and DHCP settings. There's a function
DeleteIPAddress as well in the IP Helper API but for this I need the
NTEContext of the IP address which I don't have in the program,
because I didn't add this one with AddIpAddress and couldn't find any
method to retrieve a context for a present IP. Even if I could do this
there's the same problem switching to DHCP and back to static
configuration.
Regards,
Gunnar
Post by Arkady Frenkel
You need to use wmi interfaces.
Look at EnableDHCP()/EnableStatic() of the Win32_NetworkAdapterConfiguration
Class
Arkady
Post by G***@web.de
I found some examples on how to enable DHCP on an adapter, but none of
IWbemClassObject* pInClass = NULL;
hr = pClass->GetMethod(L"EnableDHCP", 0, &pInClass, NULL);
This call returns WBEM_S_NO_ERROR, but pInClass is always NULL and so
hr = pInClass->SpawnInstance(0, &pInInst);
Fails due to pInClass is a NULL pointer. Unfortunately I found the
documentation in the msdn not very helpful, the only few examples at
all are in VB Script and nothing in C++.
Post by Arkady Frenkel
Check WMI C/C++ examples in DDK.
Arkady
Post by Vinayak
http://stackoverflow.com/questions/4967422/on-enabling-network-adpater-autoconfiguration-ip-address-getting-set
Submitted via EggHeadCafe
ASP.NET Drawing a chart using OWC11 - Office Web Components
http://www.eggheadcafe.com/tutorials/aspnet/601e9bc2-40ed-405e-b1b0-f416046b6698/aspnet-drawing-a-chart-using-owc11--office-web-components.aspx
Loading...