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

How to capture the URL and title of the current webpage being viewed?

0 Answers  


How to Check drive ready status?

0 Answers  


How to run executables created in Kylix?

0 Answers  


How to Avoid an Application Error when using EM_POSFROMCHAR ?

0 Answers  


What is the history of Delphi?

0 Answers  






How to Change the owner of a component at runtime ?

0 Answers  


Is there a programmatic way to add an alias to the IDAPI.CFG?

0 Answers  


How to Convert ASCII files to Paradox tables?

0 Answers  


Can we create stored procedures via Delphi or C++ Builder?

0 Answers  


How to Limit the amount of text entered in a TEdit?

0 Answers  


'Insufficient memory for this operation' error . what does this error mean?

0 Answers  


How to detect if a given key was pressed during application during startup?

0 Answers  


Categories