Solved

Getting network information with Delphi 1

Posted on 1999-01-07
4
148 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

11 Experts available now in Live!

Get 1:1 Help Now