1. Technology

Get computer name, Get Windows user name

By

Two tips: a) to know the name that identifies the machine in a network that is running your program, b) to get the name of the user currently working on a computer...

~~~~~~~~~~~~~~~~~~~~~~~~~
function GetComputerNetName: string;
var
  buffer: array[0..255] of char;
  size: dword;
begin
  size := 256;
  if GetComputerName(buffer, size) then
    Result := buffer
  else
    Result := ''
end;

Function GetUserFromWindows: string;
Var
   UserName : string;
   UserNameLen : Dword;
Begin
   UserNameLen := 255;
   SetLength(userName, UserNameLen) ;
   If GetUserName(PChar(UserName), UserNameLen) Then
     Result := Copy(UserName,1,UserNameLen - 1)
   Else
     Result := 'Unknown';
End;

~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» GetCallerUserName
« Set default screen saver from code

©2014 About.com. All rights reserved.