Solved

Know user logged in the Windows

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 130
Help on project with Soap 10 54
Delphi Form ownership 4 89
Breakpoint doesn't stop in my variable 3 27
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…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 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