Solved

Getting network information with Delphi 1

Posted on 1999-01-07
4
149 Views
Last Modified: 2011-09-20
I have to write an app that runs under either a Win 3.11 or Win 95 network. I have to get the user name, computer name and workgroup name from the system. Is there a way to do this that works in both cases? If not, I'd like to know how to get the info under Win 3.11, as I already know how to do that under Win 95.

Thanx
Sandman
0
Comment
Question by:sandman_br
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
heathprovost earned 50 total points
ID: 1355188
The following functions only work under Windows for Workgroups:

function GetMachineName(SysIniFileName: String): String;
var
  SYSIni: TIniFile;
begin
  SysIni := TIniFile.Create(SysIniFileName)
  Result := SysIni.ReadString('Network', 'ComputerName', 'ERROR');
end;

function GetWorkGroupName(SysIniFileName: String): String;
var
  SYSIni: TIniFile;
begin
  SysIni := TIniFile.Create(SysIniFileName)
  Result := SysIni.ReadString('Network', 'WorkGroup', 'ERROR');
end;

function GetDefaultUserName(SysIniFileName: String): String;
var
  SYSIni: TIniFile;
begin
  SysIni := TIniFile.Create(SysIniFileName)
  Result := SysIni.ReadString('Network', 'username', 'ERROR');
end;

BTW - The GetDefaultUserName does not necessarily return the current user.  It returns the user name the WFW was set up to display at logon by default.  I am looking for a solution for that and will post when found.  The other 2 functions however work fine.  NONE of these functions work under 95/98/NT.  You must first determine what OS you are running on and then go from there.

Heath
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 1355189
BTW - I forgot to Free the SysIni Objects - you should definitely modify to do that - just add SysIni.Free at the end of each function.  Sorry about that.

Heath
0
 

Author Comment

by:sandman_br
ID: 1355190
Hi heath,
your routines worked great. I'd never realize I should look at system.ini because I don't have a machine with WfW around... (go figure).
Too bad I'll have to code two programs to do the same thing.

Sandman
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 1355191
I am still looking for a simple but effective way to determine who is actually logged in.  Can you check something.  Go to a dos prompt while in windows and type "set".  This will display environment variables.  I have a feeling that there is one called "USER" that might be the key to all this.
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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

914 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

18 Experts available now in Live!

Get 1:1 Help Now