此视频展示了如何启用/禁用管理员登录帐户:
- 以管理员身份启动cmd.exe
net user Administrator /active:yes
-启用net user Administrator /active:no
-禁用
我想知道是否有可能通过程序验证这是否已经启用?
提前谢谢。
在上面和下面的评论中留下建议后的解决方案这个示例。
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 = $0002;
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:WindowsSystem32cmd.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.