473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to Assign Static IP using VC++ .net

I wanted to know how I can switch between the "Obtain an
IP address from a DHCP Server" and "Specify an IP
Address". In addition, how I can assign a static IP to the
my network adapter.
Jul 21 '05 #1
1 2187
"Shryeash Patel" <sb****@aol.com> wrote in message news:<05****************************@phx.gbl>...
I wanted to know how I can switch between the "Obtain an
IP address from a DHCP Server" and "Specify an IP
Address". In addition, how I can assign a static IP to the
my network adapter.


You can do this through the Registry using the
Microsoft.Win32.Registry and Microsoft.Win32.RegistryKey namespaces in
..NET.

First, you need to determine your network card name. This can be
found in the Registry under the HKEY_LOCAL_MACHINE (HKLM) key:
HKLM\Software\Microsoft\Windows NT\CurrentVersion\NetworkCards

Each network card on the machine is listed in a separate subkey.
Within the subkey you will see data values named Description and
ServiceName.

The ServiceName data value is then used to reference the network
card IP information in other keys. The information is stored in two
locations:
HKLM\SYSTEM\CurrentControlSet\Services\servicename , and
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Param eters\Interfaces\servicename
(where servicename is the network card ServiceName value).

These keys contain the IP data values used for the network card.
The EnableDHCP data value will be set to 1 if DHCP is enabled for that
interface. You can change it to 0 to disable DHCP. The IPAddress,
SubnetMask, and DefaultGateway values can then be set with the
approptiate static information. Be careful though, as these three
values are string arrays (a null-terminated list of null-terminated
strings). Once the values are changed, they will take effect the next
time the network card is enabled, or if the machine is rebooted.

Hope this gets you started. I show an example of querying the IP
address info from the Registry in chapter 2 of my "C# Network
Programming" book. The sample code can be freely downloaded from the
Sybex web site (obviously it is in C#, but it should not be too
difficult to convert to C++.NET). Good luck!

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyT...471433012.html
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Helmut Zeisel | last post by:
I want to build a static extension of Python using SWIG and VC++ 6.0 as described in http://www.swig.org/Doc1.3/Python.html#n8 for gcc. My file is testerl.i: ========================= %module...
17
by: Ralph | last post by:
Hi all, Recently I have tried to create a static lib using MS VC++. The following are some of the excerpt of my codes: ********* MyFirstStaticLib.c ******************* #include...
5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2;...
15
by: ad | last post by:
We can define a static member in a class. But can we define a static class, so that all members are static?
6
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the...
0
by: zhangrusi | last post by:
I have a static library that is compiled using the latest version of VC 6. It uses the multithreaded DLL versions of the run-time library, and it uses STL classes. I would like to make use of this...
5
by: Bert Jansen | last post by:
There seems to be a bug in de VS .net C++ compiler (optimization) when using inline functions that return static data. The following code demonstrates this (Win32 console app with ATL support): ...
1
by: Shryeash Patel | last post by:
I wanted to know how I can switch between the "Obtain an IP address from a DHCP Server" and "Specify an IP Address". In addition, how I can assign a static IP to the my network adapter.
9
by: t | last post by:
Lippman's C++ Primer says that if you initialize a const static data member in a class, you still need to define the member outside the class but without an initializer. I tried it using Visual...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.