Solved

Getting network information with Delphi 1

Posted on 1999-01-07
4
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to send memory stream from ics Client To ics server ? 11 203
Adoquery sql  left join does not work 25 116
Firemonkey Queue list 1 49
Posting a string with PostMessage 23 43
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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