Форум: "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("Îøèáêà LookupAccountName. Ôóíêöèÿ CalculateACLSize" +#13#10+a), PChar("Ñîîáùåíèå îá îøèáêå"), 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("Îøèáêà LookupAccountName. Ôóíêöèÿ CalculateACLSize" +#13#10+a), PChar("Ñîîáùåíèå îá îøèáêå"), 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