?
Solved

set the IP of the PC

Posted on 2004-04-28
8
Medium Priority
?
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
8 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 252 total points
ID: 10945114
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 248 total points
ID: 10946535
0
 

Author Comment

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

Expert Comment

by:Ivanov_G
ID: 10956716

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

Author Comment

by:jimy7s
ID: 10965138
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

650 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