현재 로그인한 NT도메인명을 알고 싶습니다.
제가 여러군데서 자료를 찾아보았는데 도통 보이지가 않아요.
어렵게 소스를 하나 구하긴 했는데 이것또한 제대로 되지가 않습니다.
아시는분 조언부탁드립니다.
그럼...
아래는 해당 소스입니다.
function GetCurrentDomain: string;
const
UNLEN = 255;
DNLEN = 255;
var
hProcess, hAccessToken : THandle;
InfoBuffer : PChar;
AccountName : array [0..UNLEN] of char;
DomainName : array [0..DNLEN] of char;
InfoBufferSize : Integer;
// InfoBufferSize : Cardinal;
AccountSize : Integer;
// AccountSize : Cardinal;
DomainSize : Integer;
// DomainSize : Cardianl;
snu : SID_NAME_USE;
begin
InfoBufferSize := 1000;
AccountSize := sizeof (AccountName);
DomainSize := sizeof (DomainName);
hProcess := GetCurrentProcess;
if OpenProcessToken (hProcess, TOKEN_READ, hAccessToken) then
try
GetMem (InfoBuffer, InfoBufferSize);
try
if GetTokenInformation(hAccessToken,TokenUser, InfoBuffer, InfoBufferSize, Cardinal(InfoBufferSize)) then
LookupAccountSid (Nil, PSIDAndAttributes (InfoBuffer)^.sid, AccountName, Cardinal(AccountSize),DomainName, Cardinal(DomainSize), snu)
else
RaiseLastWin32Error;
finally
FreeMem (InfoBuffer)
end;
Result := DomainName;
finally
CloseHandle (hAccessToken)
end
end;
NT DOMAIN 이라면...
요렇게 하면 되는걸루 알구 있습니다..
그럼 20000
// 기본 도메인명 가져오는 함수
function GetDefaultDomain: String;
var
MyRegistry: TRegistry;
begin
MyRegistry := TRegistry.Create;
with MyRegistry do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('SOFTWAREMicrosoftWindows NTCurrentVersionWinlogon',FALSE);
Result := MyRegistry.ReadString('DefaultDomainName');
CloseKey;
Free;
end;
end;
// 현재(로그온) 도메인명 가져오는 함수
function GetCurrentDomain: string;
var
hProcess, hAccessToken : THandle;
InfoBuffer : PChar;
AccountName : array [0..UNLEN] of char;
DomainName : array [0..DNLEN] of char;
InfoBufferSize : Integer;
AccountSize : Integer;
DomainSize : Integer;
snu : SID_NAME_USE;
begin
InfoBufferSize := 1000;
AccountSize := sizeof (AccountName);
DomainSize := sizeof (DomainName);
hProcess := GetCurrentProcess;
if OpenProcessToken (hProcess, TOKEN_READ, hAccessToken) then
try
GetMem (InfoBuffer, InfoBufferSize);
try
if GetTokenInformation(hAccessToken,TokenUser, InfoBuffer, InfoBufferSize, InfoBufferSize) then
LookupAccountSid (Nil, PSIDAndAttributes (InfoBuffer)^.sid, AccountName, AccountSize,DomainName, DomainSize, snu)
else
RaiseLastWin32Error;
finally
FreeMem (InfoBuffer)
end;
Result := DomainName;
finally
CloseHandle (hAccessToken)
end
end;
곽동수 wrote:
> 현재 로그인한 NT도메인명을 알고 싶습니다.
> 제가 여러군데서 자료를 찾아보았는데 도통 보이지가 않아요.
> 어렵게 소스를 하나 구하긴 했는데 이것또한 제대로 되지가 않습니다.
> 아시는분 조언부탁드립니다.
> 그럼...
>
> 아래는 해당 소스입니다.
>
> function GetCurrentDomain: string;
> const
> UNLEN = 255;
> DNLEN = 255;
> var
> hProcess, hAccessToken : THandle;
> InfoBuffer : PChar;
> AccountName : array [0..UNLEN] of char;
> DomainName : array [0..DNLEN] of char;
>
> InfoBufferSize : Integer;
> // InfoBufferSize : Cardinal;
> AccountSize : Integer;
> // AccountSize : Cardinal;
> DomainSize : Integer;
> // DomainSize : Cardianl;
> snu : SID_NAME_USE;
>
> begin
> InfoBufferSize := 1000;
> AccountSize := sizeof (AccountName);
> DomainSize := sizeof (DomainName);
>
> hProcess := GetCurrentProcess;
> if OpenProcessToken (hProcess, TOKEN_READ, hAccessToken) then
> try
> GetMem (InfoBuffer, InfoBufferSize);
> try
> if GetTokenInformation(hAccessToken,TokenUser, InfoBuffer, InfoBufferSize, Cardinal(InfoBufferSize)) then
> LookupAccountSid (Nil, PSIDAndAttributes (InfoBuffer)^.sid, AccountName, Cardinal(AccountSize),DomainName, Cardinal(DomainSize), snu)
> else
> RaiseLastWin32Error;
> finally
> FreeMem (InfoBuffer)
> end;
> Result := DomainName;
> finally
> CloseHandle (hAccessToken)
> end
> end;
>