Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2004.04.11;
Скачать: CL | DM;

Вниз

Получить SID пользователя...   Найти похожие ветки 

 
KPV-10k ©   (2004-03-17 23:27) [0]

Господа, помогите получить SID пользователя...
М.б. у кого есть исходник на делфях?


 
vpv   (2004-03-18 01:29) [1]

LookupAccountName

The LookupAccountName function accepts the name of a system and an account as input. It retrieves a security identifier (SID) for the account and the name of the domain on which the account was found.

BOOL LookupAccountName(
 LPCTSTR lpSystemName,
 LPCTSTR lpAccountName,
 PSID Sid,
 LPDWORD cbSid,
 LPTSTR DomainName,
 LPDWORD cbDomainName,
 PSID_NAME_USE peUse
);

Parameters
lpSystemName
[in] Pointer to a null-terminated string specifying the system. This string can be the name of a remote computer. If this string is NULL, the account name is looked up on the local system.
lpAccountName
[in] Pointer to a null-terminated string specifying the account name.
Sid
[out] Pointer to a buffer receiving the SID structure that corresponds to the account name, pointed to by the lpAccountName parameter. If this parameter is NULL, the function returns the required buffer size.
cbSid
[in, out] Pointer to a variable. On input, this value specifies the size, in bytes, of the Sid buffer. If the function fails because the buffer is too small, this variable receives the required buffer size. If the Sid parameter is NULL, this parameter must be zero.
DomainName
[out] Pointer to a buffer receiving the name of the domain where the account name is found. If this parameter is NULL, the function returns the required buffer size.
cbDomainName
[in, out] Pointer to a variable. On input, this value specifies the size, in TCHARs, of the DomainName buffer. If the function fails because the buffer is too small, this variable receives the required buffer size, including the terminating null character. If the DomainName parameter is NULL, this parameter must be zero.
peUse
[out] Pointer to a SID_NAME_USE enumerated type indicating the type of the account when the function returns.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Примерно так:

     if not LookupAccountName(ServerName,AccountName,AccountSID,SIDLength,RefDom,RefDomainLen,SIDType) then begin
       dwRes := GetLastError;
       if dwRes <> ERROR_INSUFFICIENT_BUFFER then begin
         FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,nil,dwRes,0,a,1024,nil);
         Application.MessageBox(PChar("&#206;&#248;&#232;&#225;&#234;&#224; LookupAccountName. &#212;&#243;&#237;&#234;&#246;&#232;&#255; CalculateACLSize" +#13#10+a), PChar("&#209;&#238;&#238;&#225;&#249;&#229;&#237;&#232;&#229; &#238;&#225; &#238;&#248;&#232;&#225;&#234;&#229;"), MB_OK);
         Exit;
       end;
     end;


 
vpv   (2004-03-18 13:29) [2]

Прошлый ответ не совсем правильный,
на самом деле см. здесь:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/security/lookupaccountname.asp


 
Игорь Шевченко ©   (2004-03-18 15:08) [3]


unit main;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 StdCtrls;

type
 TForm1 = class(TForm)
   Button1: TButton;
   procedure Button1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.DFM}

type
 ZString = array[0..1024] of char;

function SIDToName (const SID: PSID): string;
var
 Use : SID_NAME_USE;
 DomainName : ZString;
 DomainNameLength : DWORD;
 Name : ZString;
 NameLength : DWORD;
begin
 if not LookupAccountSid(nil, SID, Name, NameLength, DomainName,
    DomainNameLength, Use) then
   RaiseLastWin32Error;
 Result := Name;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
 AccessToken : THandle;
 Info : PSIDANDATTRIBUTES;
 ReturnLength : DWORD;
begin
 Win32Check(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, AccessToken));
 GetMem (Info, 1024);
 try
   Win32Check(GetTokenInformation(AccessToken, TokenUser, Info, 1024,
     ReturnLength));
   ShowMessage(SidToName(Info^.Sid));
 finally
   FreeMem(Info);
 end;
end;

end.



Страницы: 1 вся ветка

Текущий архив: 2004.04.11;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.062 c
4-1079462693
Александр Григоренко
2004-03-16 21:44
2004.04.11
Выравнивание в ComboBox при помощи API


3-1079512826
Rule
2004-03-17 11:40
2004.04.11
Не могу разобратся с разделителемя дробной части в FB 1


3-1079005778
alexa777
2004-03-11 14:49
2004.04.11
Ограничение длины поля


3-1082015090
sashuly
2004-04-15 11:44
2004.04.11
обновление dbf файла и SQL запрос


3-1081934441
kalishenko
2004-04-14 13:20
2004.04.11
Фильтр по дате