How to display the current user name?



How to display the current user name?..

Answer / clive

use win32 function getUserName

function MyUserFunction : String;
var
pcUserName : pChar; // temporary storage
dwMaxChars : DWORD; // length parameter
Const
MAXCHARS = 255; // max length
begin

dwMaxChars := MAXCHARS;
pcUserName := strAlloc( MAXCHARS + 1 );
try
If not getUserName( pcUserName, dwMaxChars ) Then
result := ''
else
result := String( pcUserName );
finally
strDispose( pcUserName );
end;

end;

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More Delphi Interview Questions

Can I use DLLs developed in C or C++ from Delphi?

0 Answers  


Explain the findnext method?

0 Answers  


How to Get the date of a file using Delphi?

0 Answers  


How to create an icon from a bitmap?

0 Answers  


How to Keep an application in a minimized state?

0 Answers  


How to Handle exceptions in Delphi?

0 Answers  


How to Convert a TColor value to a HTML Color string ?

0 Answers  


How to Debug CORBA clients and servers?

0 Answers  


How to Execute a program from my application?

0 Answers  


How to Add a document to the Windows 95 Start Button's documents ?

0 Answers  


How to detect if a non-menu key has been pressed?

0 Answers   IBM,


what is rounding?

1 Answers  


Categories