Solved

Know user logged in the Windows

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

12 Experts available now in Live!

Get 1:1 Help Now