Недавно добавленные исходники

•  TDictionary Custom Sort  3 227

•  Fast Watermark Sources  2 992

•  3D Designer  4 751

•  Sik Screen Capture  3 259

•  Patch Maker  3 469

•  Айболит (remote control)  3 529

•  ListBox Drag & Drop  2 904

•  Доска для игры Реверси  80 796

•  Графические эффекты  3 843

•  Рисование по маске  3 172

•  Перетаскивание изображений  2 544

•  Canvas Drawing  2 674

•  Рисование Луны  2 501

•  Поворот изображения  2 094

•  Рисование стержней  2 121

•  Paint on Shape  1 525

•  Генератор кроссвордов  2 183

•  Головоломка Paletto  1 731

•  Теорема Монжа об окружностях  2 159

•  Пазл Numbrix  1 649

•  Заборы и коммивояжеры  2 017

•  Игра HIP  1 262

•  Игра Go (Го)  1 201

•  Симулятор лифта  1 425

•  Программа укладки плитки  1 178

•  Генератор лабиринта  1 512

•  Проверка числового ввода  1 297

•  HEX View  1 466

•  Физический маятник  1 322

•  Задача коммивояжера  1 357

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Получить имя текущего пользователя 2



Оформил: DeeCo


 function GetCurrentUserName(var CurrentUserName: string): Boolean;
 var
   BufferSize: DWORD;
   pUser: PChar;
 begin
   BufferSize := 0;
   GetUserName(nil, BufferSize);
   pUser := StrAlloc(BufferSize);
   try
     Result := GetUserName(pUser, BufferSize);
     CurrentUserName := StrPas(pUser);
   finally
     StrDispose(pUser);
   end;
 end;

 procedure TForm1.Button1Click(Sender: TObject);
 var
   CurrentUserName: string;
 begin
   GetCurrentUserName(CurrentUserName);
   Label1.Caption :=  CurrentUserName;
 end;

 {*********************************************}

 { 
  Windows NT/2000/XP: 

  The GetUserNameEx function retrieves the name of the user or other 
  security principal associated with the calling thread. 
  You can specify the format of the returned name. 
  If the thread is impersonating a client, GetUserNameEx 
  returns the name of the client. 
}

 const
   NameUnknown = 0; // Unknown name type. 
  NameFullyQualifiedDN = 1;  // Fully qualified distinguished name 
  NameSamCompatible = 2; // Windows NT® 4.0 account name 
  NameDisplay = 3;  // A "friendly" display name 
  NameUniqueId = 6; // GUID string that the IIDFromString function returns 
  NameCanonical = 7;  // Complete canonical name 
  NameUserPrincipal = 8; // User principal name 
  NameCanonicalEx = 9;
   NameServicePrincipal = 10;  // Generalized service principal name 
  DNSDomainName = 11;  // DNS domain name, plus the user name 


procedure GetUserNameEx(NameFormat: DWORD;
   lpNameBuffer: LPSTR; nSize: PULONG); stdcall;
   external 'secur32.dll' Name 'GetUserNameExA';


 function LoggedOnUserNameEx(fFormat: DWORD): string;
 var
   UserName: array[0..250] of char;
   Size: DWORD;
 begin
   Size := 250;
   GetUserNameEx(fFormat, @UserName, @Size);
   Result := UserName;
 end;

 procedure TForm1.Button1Click(Sender: TObject);
 begin
   Edit1.Text := LoggedOnUserNameEx(NameSamCompatible);
 end;







Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте