Solved

Getting network information with Delphi 1

Posted on 1999-01-07
4
152 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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