type PGroupUsersInfo0 = ^_GROUP_USERS_INFO_0; _GROUP_USERS_INFO_0 = packed record grui0_name: LPWSTR; end; TGroupUsersInfo0 = _GROUP_USERS_INFO_0; GROUP_USERS_INFO_0 = _GROUP_USERS_INFO_0;
function TMainForm.GetDomainServer(const DomainName: String): String; var pwDomain:pWideChar; pwServer:pWideChar; begin GetMem(pwDomain, 512); GetMem(pwServer, 512); StringToWideChar(DomainName, pwDomain, 255); NetGetAnyDCName(nil, pwDomain, @pwServer); Result := WideCharToString(pwServer); NetApiBufferFree(pwServer); FreeMem(pwDomain, 512); end;
function TMainForm.GetGroups(DomainServer: String; UserName: String): String; type TGroupUsersInfoArray = array of TGroupUsersInfo0; var Info: PGroupUsersInfo0; Sn, Un: PWideChar; entriesread, totalentries: DWORD; I, A, B, Size: Integer; P: Pointer; begin
Sn := StringToOLEStr(DomainServer);
Un := StringToOleStr(UserName);
if NetUserGetGroups(Sn, Un, 0, @Info, DWORD(-1), entriesread, totalentries) = NO_ERROR then try if entriesread > 0 then for I := 0 to entriesread - 1 do Result := Result + TGroupUsersInfoArray(@(Info^))[I].grui0_name + ' '; finally NetApiBufferFree(Info); end; end;
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.