meni treba ovako nesto,ali negde gresim...ne treba mi ime kompjutera,nego username pod kojim sam prijavljen
Code:
FUNCTION: GetCurrentUserAndDomain - This function looks up
// the user name and domain name for the user account
// associated with the calling thread.
//
// PARAMETERS: szUser - a buffer that receives the user name
// pcchUser - the size, in characters, of szUser
// szDomain - a buffer that receives the domain name
// pcchDomain - the size, in characters, of szDomain
//
// RETURN VALUE: TRUE if the function succeeds. Otherwise, FALSE and
// GetLastError() will return the failure reason.
//
// If either of the supplied buffers are too small,
// GetLastError() will return ERROR_INSUFFICIENT_BUFFER
// and pcchUser and pcchDomain will be adjusted to
// reflect the required buffer sizes.
//
//**********************************************************************
function GetCurrentUserAndDomain(szUser : PChar; pcchUser : DWORD;
szDomain : PChar; pcchDomain: DWORD) : boolean;
var
fSuccess : boolean;
hToken : THandle;
ptiUser : PSIDAndAttributes;
cbti : DWORD;
snu : SID_NAME_USE;
begin
ptiUser := nil;
Result := false;
try
// Get the calling thread's access token.
if (not OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE,
hToken)) then
begin
if (GetLastError() <> ERROR_NO_TOKEN) then
exit;
// Retry against process token if no thread token exists.
if (not OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY,
hToken)) then
exit;
end;
// Obtain the size of the user information in the token.
if (GetTokenInformation(hToken, TokenUser, nil, 0, cbti)) then
// Call should have failed due to zero-length buffer.
Exit
else
// Call should have failed due to zero-length buffer.
if (GetLastError() <> ERROR_INSUFFICIENT_BUFFER) then
Exit;
// Allocate buffer for user information in the token.
ptiUser := HeapAlloc(GetProcessHeap(), 0, cbti);
if (ptiUser= nil) then
Exit;
// Retrieve the user information from the token.
if ( not GetTokenInformation(hToken, TokenUser, ptiUser, cbti, cbti)) then
Exit;
// Retrieve user name and domain name based on user's SID.
if ( not LookupAccountSid(nil, ptiUser.Sid, szUser, pcchUser,
szDomain, pcchDomain, snu)) then
Exit;
fSuccess := TRUE;
finally
// Free resources.
if (hToken > 0) then
CloseHandle(hToken);
if (ptiUser <> nil) then
HeapFree(GetProcessHeap(), 0, ptiUser);
end;
Result := fSuccess;
end;
[Ovu poruku je menjao savkic dana 12.12.2011. u 18:55 GMT+1]