function VersaoWindows : string; var // WinDir: array [0..MAX_PATH-1] of char; // Result: string;
PlatformId, CSDVersion: String; begin
CSDVersion := '';
case Win32Platform of VER_PLATFORM_WIN32_WINDOWS: begin if Win32MajorVersion = 4 then case Win32MinorVersion of
0: PlatformId := '9x';
10: PlatformId := '9x';
90: PlatformId := 'ME'; end else
PlatformId := '9x';
result := '9x'; end;
VER_PLATFORM_WIN32_NT: begin if Length(Win32CSDVersion) > 0 then
CSDVersion := Win32CSDVersion; if Win32MajorVersion <= 4 then
PlatformId := 'NT' else if Win32MajorVersion = 5 then case Win32MinorVersion of
0: PlatformId := '2000';
1: PlatformId := 'XP';
2: PlatformId := '2003'; else
PlatformId := '?'; end else
PlatformId := '?';
result := 'xp'; end; end; end;
function GetIP(micro: string):string; var
WSAData: TWSAData;
HostEnt: PHostEnt; // Name:string; begin
WSAStartup(2, WSAData); { SetLength(Name, 255);
Gethostname(PChar(Name), 255);
SetLength(Name, StrLen(PChar(Name)));
HostEnt := gethostbyname(PChar(Name));
}
// micro := 'Fetranspor18';
HostEnt := gethostbyname(PChar(micro)); with HostEnt^ do begin
Result :=
Format('%d.%d.%d.%d',[Byte(h_addr^[0]),Byte(h_addr^[1]),Byte(h_addr^[2]),Byte(h_addr^[3])]); end;
WSACleanup; end;
procedure tform1.ListaAmbienteRede; procedure Enumera(Res: PnetResource); var
Hnd: THandle;
NumeroEntradas: DWord;
Buffer: array[1..255] of TNetResource;
LongBuffer: DWord;
n: Integer;
S: String; begin
LongBuffer := SizeOf(Buffer); // if WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, Res, Hnd) <> No_ERROR then // raise Exception.Create('Error in network browsing') if WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, Res, Hnd) = No_ERROR then begin
NumeroEntradas := 255;
WNetEnumResource(Hnd, NumeroEntradas, @Buffer[1], LongBuffer); for n := 1 to NumeroEntradas do begin
S := string(Buffer[n].lpRemoteName); if plataforma = 'xp' then if (Buffer[1].dwType = 0) and (Copy(S, 1, 2) = '\') then
Listbox1.items.Add(Copy(S, 3, Length(S)-2)); if plataforma = '9x' then if (Buffer[1].dwType = 3) and (Copy(S, 1, 2) = '\') then
Listbox1.items.Add(Copy(S, 3, Length(S)-2)); if (Buffer[n].dwUsage and RESOURCEUSAGE_CONTAINER) = RESOURCEUSAGE_CONTAINER then
Enumera(@Buffer[n]); end; end; end; begin
Enumera(nil); end;
procedure TForm1.BitBtn1Click(Sender: TObject); var
i : shortint;
n : shortint;
tam : shortint;
nome : string;
ip : string; begin // está usando o listbox para ordenar por endereço micro
label1.visible := true;
form1.refresh;
plataforma := VersaoWindows;
ListBox1.Clear;
RichEdit1.Clear;
ListaAmbienteRede;
RichEdit1.Font.Name := 'Courier New';
RichEdit1.Font.Size := 12;
RichEdit1.Lines.Add(' ');
RichEdit1.Lines.Add(' ');
RichEdit1.Lines.Add(' Nome do Micro - Endereço IP'); for i := 0 to ListBox1.Items.Count - 1 do begin
nome := ListBox1.Items[i]; try
ip := getip(ListBox1.Items[i]); except
ip := ' '; end;
tam := length(nome); for n := tam + 1 to 20 do
nome := nome + ' ';
nome := ' ' + nome + ' - ' + ip;
RichEdit1.Lines.Add(' -------------------- ---------------');
RichEdit1.Lines.Add(nome); end;
label1.visible := false;
form1.refresh; end;
procedure TForm1.BitBtn2Click(Sender: TObject); begin
RichEdit1.print(' '); end;