Solved

set the IP of the PC

Posted on 2004-04-28
8
167 Views
Last Modified: 2010-04-05
hi experts ,
i work with client/server socket and they work together but i have a littel problem so this problem can list in 2 points :
first how to set the IP of the PC (i choose it).
second how to get the server of network IP if my PC is a part of this network.
0
Comment
Question by:jimy7s
  • 2
  • 2
8 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 63 total points
Comment Utility
The IP-address and the IP-Mask are  located in the registry :
the location is differrent for each OS (Win9X, NT4, NT5)

Example:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\NetTrans\0002

You will need to find the key where your info is stored....

Shane


procedure TForm1.SetTCPIP(IpAddress, IpMask:pchar);
var KeyHandle, SubKeyHandle:THandle;
    SubKeyName, NetworkDesc:array[0..255] of char;
    ValType, NetworkDescLength, SubKeyNameLength, index:dword;
    LastWriteTime:PFileTime;
begin
  index:=0;
  SubKeyNameLength:=255;
  RegOpenKeyEx(HKEY_LOCAL_MACHINE,
'System\CurrentControlSet\Services\Class\NetTrans', 0, KEY_ALL_ACCESS,
KeyHandle);
  while (RegEnumKeyEx(KeyHandle, index, SubKeyName, SubKeyNameLength, nil,
nil, nil, LastWriteTime)<>ERROR_NO_MORE_ITEMS) do
  begin
    RegOpenKeyEx(KeyHandle, SubKeyName, 0, KEY_ALL_ACCESS, SubKeyHandle);

    NetWorkDescLength:=255;
    RegQueryValueEx(SubKeyHandle, 'DriverDesc', nil, @ValType, @NetworkDesc,
@NetworkDescLength);
    if (NetworkDesc='TCP/IP') then break;

    inc(index);
    SubKeyNameLength:=255;
  end;
  if (NetworkDesc<>'TCP/IP') then
  begin
    messagebox(0,'TCP/IP protocol is not installed on your computer','',0);
    exit;
  end;
  NetWorkDescLength:=255;
  RegSetValueEx(SubKeyHandle, 'IPAddress', 0, REG_SZ, IpAddress, 15);
  RegSetValueEx(SubKeyHandle, 'IPMask', 0, REG_SZ, IpMask, 15);
end;


then call the procedure on a button click or so...

SetTCPIP('255.254.253.255', '255.255.255.255');//IP, Subnetmask...


Shane
0
 
LVL 12

Assisted Solution

by:Ivanov_G
Ivanov_G earned 62 total points
Comment Utility
0
 

Author Comment

by:jimy7s
Comment Utility
guys if i set IP by force did the Internet connection effecte
0
 
LVL 12

Expert Comment

by:Ivanov_G
Comment Utility

   The same way it is affected if you change the IP address manually from Network Neighbourhood...
0
 

Author Comment

by:jimy7s
Comment Utility
Thanks shaneholmes And Ivanov ;
bytheway shaneholmes if i use widows Xp what is the change ?
is the the code still as it was . Cause the error occur when i compiled this segment of code.
           and thanks for you both ;
                        jimmy
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now