Solved

Getting network information with Delphi 1

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
URL for downloading Google Chrome for Win XP 2 152
Reconfigure Delphi Install? 2 51
Delphi: Connect to running MS Outlook 4 77
Tvertscrollbox like a whatsapp layout 5 25
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

816 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