Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get User Name

Posted on 2004-04-21
7
Medium Priority
?
151 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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

715 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