• Delphi


    (*
     * 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

  • 相关阅读:
    struts2.1.6存在中文乱码的bug
    记Spring下autowire为name时的一个现象
    AOP注解不起作用的debug结果
    占位
    占位
    Hibernate学习小结
    Struts2学习笔记
    金尚网上商城项目第一章小结
    JavaWeb 学习的第一阶段总结
    大话设计模式 笔记——策略模式
  • 原文地址:https://www.cnblogs.com/findumars/p/5755088.html
Copyright © 2020-2023  润新知