473,806 Members | 2,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2226
"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_MACH INE (HKLM) key:
HKLM\Software\M icrosoft\Window s NT\CurrentVersi on\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\Cur rentControlSet\ Services\servic ename, and
HKLM\SYSTEM\Cur rentControlSet\ Services\Tcpip\ Parameters\Inte rfaces\servicen ame
(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
2507
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 testerl extern int hz(int i);
17
2199
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 <stdlib.h> #include <string.h>
5
1926
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; // ... public static MyObject Object400;
15
3346
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
4413
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 same invocation from a DistantlyRelated class. What actually happened was that the compiler produced: error C2247: 'A::function' not accessible because 'CloselyRelated' uses 'private' to inherit from 'A' I'm guessing that the above compiler...
0
1477
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 static library in a VS .NET 2003 managed C++ project. Currently, I am just linking the compiled .lib file into my VC 7 project. (This is the simplest approach, as it is not practical to move the static library project to VC 7 at this time.) My VC...
5
1930
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): #include "stdafx.h" #include <atltime.h> int _tmain(int argc, _TCHAR* argv) {
1
332
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
6903
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 C++ 2005 Express edition and get this error: 1>Account.obj : error LNK2005: "private: static int const Account::period" (?period@Account@@0HB) already defined in Account Main.obj
0
9719
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10369
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.