Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2004.04.11;
Скачать: [xml.tar.bz2];

Вниз

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

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

Господа, помогите получить 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 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


 
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.


 
Игорь Шевченко ©   (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 вся ветка

Форум: "WinAPI";
Текущий архив: 2004.04.11;
Скачать: [xml.tar.bz2];

Наверх




Память: 0.47 MB
Время: 0.034 c
14-1082260151
Думкин
2004-04-18 07:49
2004.05.09
С днем рождения! 18 апреля.


9-1071390469
Nvart
2003-12-14 11:27
2004.05.09
Крестики-нолики


1-1082547148
Axil
2004-04-21 15:32
2004.05.09
Общий скрол окна и его фрейма


7-1079501839
Zyb
2004-03-17 08:37
2004.05.09
Запуск закрытие приложения


8-1076071591
mfasakhov
2004-02-06 15:46
2004.05.09
Воспроизвести AVI на видеовыходе Pinnacle DV500





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский