Ich stehe vor einem Rätsel. Mit der
API NetUserSetInfo versuche ich Details für einen Benutzer Account zu setzen. NetUserSetInfo erwartet unter anderem folgende Struktur:
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;
Diese fülle ich wie folgt:
Delphi-Quellcode:
function SetDetails: TUserInfo3;
begin
ZeroMemory(@result, sizeof(result));
result.usri3_name := PWideChar(WideString(GetText(ID_EDT_USER)));
result.usri3_full_name := PWideChar(WideString(GetText(ID_EDT_FULLNAME)));
result.usri3_comment := PWideChar(WideString(GetText(ID_EDT_DESCRIPTION)));
result.usri3_home_dir := PWideChar(WideString(GetText(ID_EDT_HOMEDIR)));
result.usri3_script_path :=
PWideChar(WideString(GetText(ID_EDT_SCRIPT_PATH)));
if GetCheck(ID_CHK_MUST_CHANGE_PW) then
result.usri3_password_expired := 1
else
result.usri3_password_expired := 0;
if GetCheck(ID_CHK_CANT_CHANGE_PW) then
result.usri3_flags := result.usri3_flags or UF_PASSWD_CANT_CHANGE;
if GetCheck(ID_CHK_PW_DONT_EXPIRE) then
result.usri3_flags := result.usri3_flags or UF_DONT_EXPIRE_PASSWD;
if GetCheck(ID_CHK_ACCOUNT_DISABLED) then
result.usri3_flags := result.usri3_flags or UF_ACCOUNTDISABLE;
end;
Dann die eigentliche Funktion:
Delphi-Quellcode:
function SetUserInfo(Server, User: string; UserInfo: TUserInfo3):
NET_API_STATUS;
var
ui3: Pointer;
begin
ui3 := nil;
result := NERR_BASE;
if User <> '' then
begin
if NetUserGetInfo(PWideChar(WideString(Server)),
PWideChar(WideString(User)), 3, ui3) = NERR_SUCCESS then
begin
PUserInfo3(ui3)^.usri3_name := UserInfo.usri3_name;
PUserInfo3(ui3)^.usri3_full_name := UserInfo.usri3_full_name;
PUserInfo3(ui3)^.usri3_password := UserInfo.usri3_password;
PUserInfo3(ui3)^.usri3_home_dir := UserInfo.usri3_home_dir;
PUserInfo3(ui3)^.usri3_comment := UserInfo.usri3_comment;
PUserInfo3(ui3)^.usri3_usr_comment := UserInfo.usri3_comment;
PUserInfo3(ui3)^.usri3_priv := UserInfo.usri3_priv;
PUserInfo3(ui3)^.usri3_script_path := UserInfo.usri3_script_path;
PUserInfo3(ui3)^.usri3_auth_flags := UserInfo.usri3_auth_flags;
PUserInfo3(ui3)^.usri3_parms := UserInfo.usri3_parms;
PUserInfo3(ui3)^.usri3_workstations := UserInfo.usri3_workstations;
PUserInfo3(ui3)^.usri3_acct_expires := UserInfo.usri3_acct_expires;
PUserInfo3(ui3)^.usri3_max_storage := UserInfo.usri3_max_storage;
PUserInfo3(ui3)^.usri3_home_dir_drive := UserInfo.usri3_home_dir_drive;
PUserInfo3(ui3)^.usri3_profile := UserInfo.usri3_profile;
PUserInfo3(ui3)^.usri3_password_expired := UserInfo.usri3_password_expired;
PUserInfo3(ui3)^.usri3_flags := UserInfo.usri3_flags;
result := NetUserSetInfo(PWideChar(WideString(Server)),
PWideChar(WideString(User)), 3, ui3, nil);
end;
end;
end;
Es kommt alles richtig an. Stoppe ich hier:
PUserInfo3(ui3)^.usri3_name := UserInfo.usri3_name; und schaue mir die Werte der felder der Struktur an, stimmen sie alle. Aber so bald der
full_name zugewiesen wurde, stimmen die Werte der anderen Felder nicht mehr. Teilweise steht Schrott drinne teilweise sachen im Klartext, die irgendwo anders im Programm auftauchen, wie der Computername zum Beispiel.
Ich habe keinen blassen Schimmer, was da passiert und warum.