1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71:
| function SetWinlogonPassword(const Server, Password: WideString): Boolean; var oa : TLSAObjectAttributes; hPolicy : LSA_HANDLE; usServer : TLSAUnicodeString; usKeyName : TLSAUnicodeString; usPassWord : TLSAUnicodeString; Status : NTSTATUS; begin ZeroMemory(@oa, sizeof(oa)); oa.Length := sizeof(oa); try RtlInitUnicodeString(@usServer, PWideChar(Server)); Status := LsaOpenPolicy(usServer, oa, POLICY_CREATE_SECRET, hPolicy); if (NT_SUCCESS(Status)) then begin RtlInitUnicodeString(@usKeyName, 'DefaultPassword'); RtlInitUnicodeString(@usPassWord, PWideChar(Password)); Status := LsaStorePrivateData(hPolicy, usKeyName, usPassword); end; finally LsaClose(hPolicy); end; Result := NT_SUCCESS(Status); end;
function SetAutoWinlogon(Server: WideString; Activate: Boolean; Username, Password: WideString): Boolean; var usPassword : TLSAUnicodeString; usServer : TLSAUnicodeString; reg : TMpuRegistry; begin Result := False; reg := TMpuRegistry.CreateW(Server, HKEY_LOCAL_MACHINE); if (Assigned(reg)) then try reg.Connect; if reg.OpenKeyW('Software\Microsoft\Windows NT\CurrentVersion\Winlogon', KEY_WRITE) = 0 then begin if Username <> '' then reg.WriteStringW('DefaultUserName', Username) else reg.DeleteValueName('DefaultUserName');
if Server <> '' then reg.WriteStringW('DefaultDomainName', Server) else reg.DeleteValueName('DefaultDomainName');
RtlInitUnicodeString(@usPassword, PWideChar(Password)); RtlInitUnicodeString(@usServer, PWideChar(Server)); if SetWinlogonPassword(usServer.Buffer, usPassword.Buffer) then begin Result := True; end; reg.DeleteValueName('DefaultPassword');
reg.WriteString('AutoAdminLogon', IntToStr(ord(Activate))); end; finally reg.Free; end; end; |