Title: Get list of names of all computers within your Network
Question: How can I obtain the names of all of the computers within my
Network, even if not all of the computers are switched on
Answer:
Here is how. Just compy the 3 files with eg Notepad into the 3 files
into one directory...
Unit1.pas.........
unit Unit1; //programmed by Omer Yasar Can
//Advantage: Not all of the Computers within your Network have
//to be switched on
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls;
type
TForm1 = class(TForm)
BitBtn_GetAllComputerNames: TBitBtn;
Memo1: TMemo;
StatusBar1: TStatusBar;
procedure BitBtn_GetAllComputerNamesClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
Registry;
procedure TForm1.BitBtn_GetAllComputerNamesClick(Sender: TObject);
var
reg: TRegistry;
Strs: TStrings;
begin
// Creates a TRegistry Object, erzeugt ein a TRegistry Objekt
reg := TRegistry.Create;
try
Strs:= TStringList.Create;
// set the the Mainkey, bestimmt den Hauptschlssel
reg.RootKey := HKEY_CURRENT_USER;
// Open a key, den Schlssel ffnen
reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\ComputerDescriptions', True);
reg.GetValueNames(Strs); // memo1.Lines.Assign(Strs);
// Close the key, Schlssel schliessen
reg.CloseKey;
finally
// and free the TRegistry Object, das TRegistry Objekt freigeben
reg.Free;
Strs.Free;
end;
end;
end.
Readout_Computernames_Registry.dpr.........
program Readout_Computernames_Registry;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
Unit1.dfm........
object Form1: TForm1
Left = 446
Top = 509
Width = 282
Height = 167
Caption = 'Delphi -- HOW TO -- Network'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Shell Dlg 2'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object BitBtn_GetAllComputerNames: TBitBtn
Left = 0
Top = 0
Width = 273
Height = 25
Caption = 'Get me the Names of all the Computers within Network'
TabOrder = 0
OnClick = BitBtn_GetAllComputerNamesClick
end
object Memo1: TMemo
Left = 0
Top = 24
Width = 273
Height = 89
Lines.Strings = (
'Memo1')
TabOrder = 1
end
object StatusBar1: TStatusBar
Left = 0
Top = 114
Width = 274
Height = 19
Panels = item
Text = 'Readout all computernames withing Network'
Width = 50
end
end
end