Solved

Know user logged in the Windows

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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