Solved

set the IP of the PC

Posted on 2004-04-28
8
169 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

24 Experts available now in Live!

Get 1:1 Help Now