Solved

Know user logged in the Windows

Posted on 2003-11-20
6
266 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

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

691 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