如何检查是否启用了管理员帐户登录?

How check if login with Adminstrator account is enabled?

This video 显示如何 enable/disable 管理员登录帐户:

  1. 以管理员身份启动cmd.exe
  2. net user Administrator /active:yes - 启用
  3. net user Administrator /active:no - 禁用

我想知道是否有可能以编程方式验证此功能是否已启用?

提前致谢。

根据上面评论中留下的建议和以下 this 示例的解决方案。

program Project1;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  Windows,
  ShellAPI,
  SysUtils;

type
  TUserInfo1 = record
    usri1_name: PWideChar;
    usri1_password: PWideChar;
    usri1_password_age: Cardinal;
    usri1_priv: Cardinal;
    usri1_home_dir: PWideChar;
    usri1_comment: PWideChar;
    usri1_flags: Cardinal;
    usri1_script_path: PWideChar;
  end;

  PUserInfo1 = ^TUserInfo1;

function NetUserGetInfo(servername: PWideChar; username: PWideChar; level: Cardinal; var bufptr: PUserInfo1): Cardinal; stdcall; external 'netapi32.dll' name 'NetUserGetInfo';

function IsAdminLoginEnabled: Boolean;
const
  UF_ACCOUNTDISABLE = [=10=]02;
  username = 'Administrator';
var
  ui1: PUserInfo1;
begin
  Result := False;
  if NetUserGetInfo(nil, username, 1, ui1) = 0 then
    Result := (ui1.usri1_flags and UF_ACCOUNTDISABLE) <> UF_ACCOUNTDISABLE;
end;

const
  CmdExePath = 'C:\Windows\System32\cmd.exe';
  AdminLoginEnable = '/C net user Administrator /active:yes';
  AdminLoginDisable = '/C net user Administrator /active:no';

begin
  try
    ShellExecute(0, nil, CmdExePath, AdminLoginEnable, nil, SW_HIDE);
    Sleep(2000);
    Writeln(IsAdminLoginEnabled);
    ShellExecute(0, nil, CmdExePath, AdminLoginDisable, nil, SW_HIDE);
    Sleep(2000);
    Writeln(IsAdminLoginEnabled);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;

end.