Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Set Static IP configuration, Enable/Disable DHCP

1,341 views
Skip to first unread message

Gunnar_...@web.de

unread,
Mar 29, 2007, 4:12:36 PM3/29/07
to
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

unread,
Mar 30, 2007, 3:39:53 AM3/30/07
to
You need to use wmi interfaces.
Look at EnableDHCP()/EnableStatic() of the Win32_NetworkAdapterConfiguration
Class
Arkady

<Gunnar_...@web.de> wrote in message
news:1175199156.5...@n59g2000hsh.googlegroups.com...

Gunnar_...@web.de

unread,
Apr 1, 2007, 12:53:53 PM4/1/07
to
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++.

Arkady Frenkel

unread,
Apr 2, 2007, 1:59:57 AM4/2/07
to
Check WMI C/C++ examples in DDK.
Arkady

<Gunnar_...@web.de> wrote in message
news:1175446433.4...@p77g2000hsh.googlegroups.com...

Vinayak

unread,
Feb 14, 2011, 6:29:58 AM2/14/11
to
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


>> On Friday, March 30, 2007 2:39 AM Arkady Frenkel wrote:

>> You need to use wmi interfaces.
>> Look at EnableDHCP()/EnableStatic() of the Win32_NetworkAdapterConfiguration
>> Class
>> Arkady


>>> On Sunday, April 01, 2007 12:53 PM Gunnar_Frenze wrote:

>>> 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++.
>>>
>>>
>>>
>>>
>>>
>>> On 30 Mrz., 09:39, "Arkady Frenkel" <arka...@hotmailxdotx.com> wrote:


>>>> On Monday, April 02, 2007 1:59 AM Arkady Frenkel wrote:

>>>> 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

unread,
Feb 14, 2011, 6:32:05 AM2/14/11
to
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

> On Thursday, March 29, 2007 3:12 PM Gunnar_Frenze wrote:

>> On Friday, March 30, 2007 2:39 AM Arkady Frenkel wrote:

>> You need to use wmi interfaces.
>> Look at EnableDHCP()/EnableStatic() of the Win32_NetworkAdapterConfiguration
>> Class
>> Arkady


>>> On Sunday, April 01, 2007 12:53 PM Gunnar_Frenze wrote:

>>> 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++.
>>>
>>>
>>>
>>>
>>>
>>> On 30 Mrz., 09:39, "Arkady Frenkel" <arka...@hotmailxdotx.com> wrote:


>>>> On Monday, April 02, 2007 1:59 AM Arkady Frenkel wrote:

>>>> Check WMI C/C++ examples in DDK.
>>>> Arkady


>>>>> On Monday, February 14, 2011 6:29 AM Vinayak wrote:

>>>>> 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


>>>>> 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

0 new messages