Link to home
Start Free TrialLog in
Avatar of sandman_br
sandman_br

asked on

Getting network information

My Delphi program has to run in a Microsoft Win95 network and needs the following data: user name, computer name and workgroup name. How can I retrieve this info using Delphi code?
ASKER CERTIFIED SOLUTION
Avatar of jecksom
jecksom

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jecksom
jecksom

getcomputername and getusername , also could give part of information you looking for
procedure TForm1.FormCreate(Sender: TObject);
 var
     compbuf,userbuf: array [0..16] of Char;
     compsize,usersize: DWORD;
 begin
     compsize := 16;
     usersize := 16;
     GetComputerName(compbuf, compSize);
     GetUserName(userbuf, userSize);
     showmessage(userbuf+' '+compbuf);
 end;

jecksom

The NetQueryDsplayInformation is a Windows Nt API only it will not return on Win 95 however u are correct in the get computer/username API

Sandman_br

Here is some code to get the username and Computername

procedure TForm1.FormCreate(Sender: TObject);
var
 NameBuf, NameBuf2: array[0..80] of Char;
 SizeBuf, SizeBuf2: LongWord;
begin
  SizeBuf := Sizeof(NameBuf);
   GetUserName(NameBuf, SizeBuf);
    Edit1.Text := NameBuf;
     SizeBuf2 := Sizeof(NameBuf2);
      GetComputerName(NameBuf2, SizeBuf2);
       Edit2.Text := NameBuf2;

end;

The Workgroup I think needs to be read from the registry...

it sits under the path HKEY_LOCAL_MACHINE\system\CurrentControlSet\Services\VxD\VNETSUP\
the string to read is Workgroup...

Later
BoRiS


C sources for network info:    http://www.mvps.org/win32/
Avatar of sandman_br

ASKER

Thanks a lot! I had tried getusername () and getcomputername () at first, but
only getusername () worked... maybe because I was trying to reuse the buffer
and size variables I passed for the first call in the second call. It only
worked with separate variables for each call, as you suggested... but now it's fine. :)
As for the workgroup name, BoRiS's suggestion worked plain great. Kudos to ronit
for the cool link. Thanx again, guys!

C ya,
Sandman