Solved

Get User Name

Posted on 2004-04-21
7
145 Views
Last Modified: 2010-04-05
How can I get current  UserName? Windows UserName?
0
Comment
Question by:nthiyab
  • 3
7 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 10877157
function GetLocalName: string;
var
  i: cardinal;
  sUser: array[0..255] of Char;
begin
  try
    i := 255;
    GetUserName(sUser, i);
    result := sUser;
  except
    result := '';
  end;
end;

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 10877172
Or:

function GetLocalUser: string;
var
  i : cardinal;
begin
  try
    i:=255;
    SetLength(result,i);
    GetUserName(PChar(result),i);
    SetLength(result,(i-1));
  except
    result := '';
  end;
end;
0
 

Expert Comment

by:amjedmsa
ID: 10877174
here is the computer names as well


function Cn String;
var
  Size DWord;
begin
  Size = MAX_PATH;
  SetLength(Result, Size);
  if not GetComputerName(PChar(Result), Size) then Size = 0;
  SetLength(Result, Size);
end;
0
 
LVL 17

Expert Comment

by:geobul
ID: 13194123
I'm pretty sure I've answered the question.

Regards, Geo
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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

862 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

24 Experts available now in Live!

Get 1:1 Help Now