Solved

Get User Name

Posted on 2004-04-21
7
149 Views
Last Modified: 2010-04-05
How can I get current  UserName? Windows UserName?
0
Comment
Question by:nthiyab
[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
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

Technology Partners: 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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

751 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