Solved

Know user logged in the Windows

Posted on 2003-11-20
6
265 Views
Last Modified: 2010-04-05
Hi,

How can I know the user who is logged in the Windows with the Delphi ???


Thank´s!!!

Rafael Schardosin
Porto Alegre - Brazil
0
Comment
Question by:schardosin
[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
6 Comments
 
LVL 3

Accepted Solution

by:
raidos earned 25 total points
ID: 9786826
Function ReturnUser:String;
Var
  PC: PChar;
  Car: Cardinal;
Begin
  Car := 0;
  PC := Nil;
  GetUserName(PC,Car);
  If Car <> 0 Then Begin
    GetMem(PC,Car);
    GetUserName(PC,Car);
    Result := String(PC);
    FreeMem(PC);
  End Else Result := 'UNKNOWN';
End;


Procedure OnClick(Sender: TObject);
Begin
  ShowMessage(ReturnUser);
end;
0
 

Assisted Solution

by:riper747
riper747 earned 25 total points
ID: 9794134
you can use some thing like this ,

function getuserlogin:string;
var pcusername:pchar; xchars:dwords; valor:integer;
begin
valor:=255;
xchars:=255;
pcusername:=strAlloc(valor+1);
getusername(pcusername,xchars);
result:=string(pcusername);
end;

Procedure onclick(sender:tobject)
begin
 edit1.text:=getuserlogin();
end;


0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 9796537
That was easy, especially since this question has been answered many times before... ;-)
0
 
LVL 2

Expert Comment

by:TheLeader
ID: 9801139
Function LoggedName : string;
var
   sizeOfuser : cardinal;
   user : array[0..255] of char;
begin
   sizeOfuser := sizeof(user);
   IF getusername(user,sizeOfuser) = true then
   Begin
      Result := string(user);
   End
   Else
      Result := 'NO USER';
end; { LoggedName }

now you just need to call the function
ex:
   Edit1.Text := LoggedName;
tested on winxp
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

Suggested Solutions

Title # Comments Views Activity
can't find the executable in Simulator 1 128
Find and Replace Stream with 0s 8 86
update joined tables 2 72
QuickReport, Delphi, Shape 12 47
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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