码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi - GetUserNameEx(学一下导出Windows API,以及Array Char充当缓冲区的用法,下标必须从零开始)

时间:2016-08-10 00:50:33      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

(*
 * Author  : http://www.michael-puff.de
 * Date    : 2006-03-29
 * License : PUBLIC DOMAIN
 *)

function GetUserNameEx(NameFormat: DWORD; lpNameBuffer: LPSTR; var nSize: DWORD): Boolean; stdcall; external
  ‘secur32.dll‘ Name ‘GetUserNameExA‘;

function GetLoggedOnUserNameEx(fFormat: DWORD; var Username: string): DWORD;

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

var
  Size              : DWORD;
  Buffer            : array[0..1024] of Char;
begin
  Result := 0;
  Size := sizeof(Buffer);
  if GetUserNameEx(fFormat, Buffer, Size) then
    SetString(Username, Buffer, Size)
  else
    Result := GetLastError;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Username          : string;
  err               : DWORD;
begin
  err := GetLoggedOnUserNameEx(3, Username);
  if err = 0 then
    ShowMessage(Username)
  else
    ShowMessage(SysErrorMessage(err));
end;

http://www.michael-puff.de/Programmierung/Delphi/Code-Snippets/GetUserNameEx.shtml

Delphi - GetUserNameEx(学一下导出Windows API,以及Array Char充当缓冲区的用法,下标必须从零开始)

标签:

原文地址:http://www.cnblogs.com/findumars/p/5755088.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!