PC Review


Reply
Thread Tools Rate Thread

How to Assign Static IP using VC++ .net

 
 
Shryeash Patel
Guest
Posts: n/a
 
      23rd Dec 2003
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.
 
Reply With Quote
 
 
 
 
Rich Blum
Guest
Posts: n/a
 
      24th Dec 2003
"Shryeash Patel" <(E-Mail Removed)> wrote in message news:<050501c3c96a$4a29b6f0$(E-Mail Removed)>...
> 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\Parameters\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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot assign static IP Address Adriano Gardos Microsoft Windows 2000 Networking 1 12th Jul 2007 06:15 PM
Assign a Static Drive Letter =?Utf-8?B?Qm8tYmFubmll?= Windows XP Customization 1 9th Aug 2005 02:30 AM
Dynamically assign static IP? Chris Shearer Cooper Windows XP Networking 9 31st Jul 2005 06:49 PM
Cannot assign static IP Alan Franklin Microsoft Windows 2000 Networking 0 9th Dec 2004 07:19 AM
How to assign A Static IP Bob Microsoft Windows 2000 Advanced Server 2 23rd Sep 2004 04:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:54 PM.