Чтение онлайн

ЖАНРЫ

Советы по Delphi. Версия 1.4.3 от 1.1.2001

Озеров Валентин

Шрифт:

printf("Cannot open process token, quitting [%lu].\n", GetLastError);

return 1;

}

 }

 // normally, I should get the size of the group list first, but ...

 l = sizeof rawGroupList;

 if (!GetTokenInformation(hTok, TokenGroups, &groupList, l, &l)) {

printf( "Cannot get group list from token [%lu].\n", GetLastError);

return 1;

 }

 // here, we cobble up a SID for the Administrators group, to compare to.

 if (!AllocateAndInitializeSid(&ntAuth, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pAdminSid )) {

printf("Cannot create SID for Administrators [%lu].\n", GetLastError);

return 1;

 }

 // now, loop through groups in token and compare

 found = 0;

 for (i = 0; i < groupList.GroupCount; ++i) {

if (EqualSid(pAdminSid, groupList.Groups[i].Sid)) {

found = 1;

break;

}

 }

 FreeSid(pAdminSid);

 CloseHandle(hTok);

 return !!found;

}

int main {

 bool j, l;

 j = jerry_coffin_method;

 l = look_at_token_method;

 printf("NetUserGetInfo: The current user is %san Administrator.\n", j? "": "not ");

 printf("Process token: The current user is %sa member of the Administrators group.\n", l? "": "not ");

 return 0;

}

//****************************************************************************//
 

Как

узнать язык Windows по умолчанию?

Одной строкой 

Nomadic лаконично отвечает:

GetSystemDefaultLCID

GetLocaleInfo

GetLocalUserList — возвращает список пользователей (Windows NT, Windows 2000)

Кондратюк Виталий предлагает следующий код:

unit Func;

interface

uses Sysutils, Classes, Stdctrls, Comctrls, Graphics, Windows;

////////////////////////////////////////////////////////////////////////////////

{$EXTERNALSYM NetUserEnum}

function NetUserEnum(servername: LPWSTR; level, filter: DWORD; bufptr: Pointer; prefmaxlen: DWORD; entriesread, totalentries, resume_handle: LPDWORD): DWORD; stdcall; external 'NetApi32.dll' Name 'NetUserEnum';

function NetApiBufferFree(Buffer: Pointer{LPVOID}): DWORD; stdcall; external 'NetApi32.dll' Name 'NetApiBufferFree';

////////////////////////////////////////////////////////////////////////////////

procedure GetLocalUserList(ulist: TStringList);

implementation

//------------------------------------------------------------------------------

//
возвращает список пользователей локального хоста

//------------------------------------------------------------------------------

procedure GetLocalUserList(ulist: TStringList);

const

 NERR_SUCCESS = 0;

 FILTER_TEMP_DUPLICATE_ACCOUNT = $0001;

 FILTER_NORMAL_ACCOUNT = $0002;

 FILTER_PROXY_ACCOUNT = $0004;

 FILTER_INTERDOMAIN_TRUST_ACCOUNT = $0008;

 FILTER_WORKSTATION_TRUST_ACCOUNT = $0010;

 FILTER_SERVER_TRUST_ACCOUNT = $0020;

type

 TUSER_INFO_10 = record

usri10_name, usri10_comment, usri10_usr_comment, usri10_full_name: PWideChar;

 end;

 PUSER_INFO_10 = ^TUSER_INFO_10;

var

 dwERead, dwETotal, dwRes, res: DWORD;

 inf: PUSER_INFO_10;

 info: Pointer;

 p: PChar;

 i: Integer;

begin

 if ulist=nil then Exit;

 ulist.Clear;

 info := nil;

 dwRes := 0;

 res := NetUserEnum(nil, 10, FILTER_NORMAL_ACCOUNT, @info, 65536, @dwERead, @dwETotal, @dwRes);

 if (res<>NERR_SUCCESS) or (info=nil) then Exit;

 p := PChar(info);

 for i:=0 to dwERead-1 do begin

inf := PUSER_INFO_10(p + i*SizeOf(TUSER_INFO_10));

ulist.Add(WideCharToString(PWideChar((inf^).usri10_name)));

 end;

 NetApiBufferFree(info);

end;

end.
 

Поделиться с друзьями: