Solved

set the IP of the PC

Posted on 2004-04-28
8
174 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 63 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 62 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

726 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