Registriert seit: 29. Mai 2002
37.621 Beiträge
Delphi 2006 Professional
|
Re: Freigeben von Pointern von API Funktionen
18. Okt 2004, 10:49
Also noch mal alles zusammen:
Delphi-Quellcode:
type
TUserInfo3 = record
usri3_name: LPWSTR;
usri3_password: LPWSTR;
usri3_password_age: DWORD;
usri3_priv: DWORD;
usri3_home_dir: LPWSTR;
usri3_comment: LPWSTR;
usri3_flags: DWORD;
usri3_script_path: LPWSTR;
usri3_auth_flags: DWORD;
usri3_full_name: LPWSTR;
usri3_usr_comment: LPWSTR;
usri3_parms: LPWSTR;
usri3_workstations: LPWSTR;
usri3_last_logon: DWORD;
usri3_last_logoff: DWORD;
usri3_acct_expires: DWORD;
usri3_max_storage: DWORD;
usri3_units_per_week: DWORD;
usri3_logon_hours: PBYTE;
usri3_bad_pw_count: DWORD;
usri3_num_logons: DWORD;
usri3_logon_server: LPWSTR;
usri3_country_code: DWORD;
usri3_code_page: DWORD;
usri3_user_id: DWORD;
usri3_primary_group_id: DWORD;
usri3_profile: LPWSTR;
usri3_home_dir_drive: LPWSTR;
usri3_password_expired: DWORD;
end;
PUserInfo3 = ^TUserInfo3;
Delphi-Quellcode:
function GetUserInfo(Server, User: string): TUserInfo3;
var
ui3: Pointer;
NetError: DWORD;
begin
if User <> '' then
begin
try
NetError := NetUserGetInfo(PWideChar(WideString(Server)),
PWideChar(WideString(User)), 3, ui3);
if NetError = NERR_SUCCESS then
begin
result.usri3_name := PUserInfo3(ui3)^.usri3_name;
result.usri3_full_name := PUserInfo3(ui3)^.usri3_full_name;
result.usri3_comment := PUserInfo3(ui3)^.usri3_comment;
result.usri3_home_dir := PUserInfo3(ui3)^.usri3_home_dir;
result.usri3_password_age := PUserInfo3(ui3)^.usri3_password_age;
result.usri3_last_logon := PUserInfo3(ui3)^.usri3_last_logon;
result.usri3_num_logons := PUserInfo3(ui3)^.usri3_num_logons;
result.usri3_password_expired :=
PUserInfo3(ui3)^.usri3_password_expired;
result.usri3_flags := DWORD(PUserInfo3(ui3)^.usri3_flags and
UF_PASSWD_CANT_CHANGE = UF_PASSWD_CANT_CHANGE);
result.usri3_flags := DWORD(PUserInfo3(ui3)^.usri3_flags and
UF_DONT_EXPIRE_PASSWD = UF_DONT_EXPIRE_PASSWD);
result.usri3_flags := DWORD(PUserInfo3(ui3)^.usri3_flags and
UF_ACCOUNTDISABLE = UF_ACCOUNTDISABLE);
end;
finally
//NetApiBufferFree(ui3);
end;
end;
end;
Und der Aufruf:
Delphi-Quellcode:
type
TUser = packed record
Name: String[255];
UserGroups: string[255];
end;
TUsers = array of TUser;
[..]
function GetUsers(Computer: String): TUsers;
var
Users: TStringArray;
i: Integer;
ui3: TUserInfo3;
UserGroups: TStringArray;
s: PWideChar;
begin
UserGroups := nil;
Users := EnumUsers(Computer, FILTER_NORMAL_ACCOUNT);
setlength(result, length(Users));
for i := 0 to length(Users) - 1 do
begin
ui3 := GetUserInfo(Computer, Users[i]);
result[i].Name := String(ui3.usri3_name);
end;
end;
Michael Ein Teil meines Codes würde euch verunsichern.
|
|
Zitat
|