Use Variants, ActiveDs_TLB, COMObj, Ole2, adshlp;
Var
ActiveUsers: TStringlist;
ComputerName: Olevariant;
UserName: Olevariant;
UserDomain: Olevariant;
function UserLoggedIn(Username: string): string;
var
target: string;
UserObj: Olevariant;
LoggedIn: Olevariant;
begin
target := format('
WinNT://%s/%s', [ComputerName, UserName]);
UserObj := ADsHlp.GetObject(target);
try
LoggedIn := UserObj.LastLogin;
result := string(LoggedIn);
finally
UserObj := Unassigned;
end;
end;
function GetActiveUsers: TStringlist;
var
HostInfo: TWKSTA_USER_INFO_0;
WshNetWork: Olevariant;
i: integer;
LogIn: string;
begin
result := TStringlist.create;
WshNetWork := CreateOleObject('WScript.Network');
try
ComputerName := WshNetWork.Computername;
UserName := WshNetWork.UserName;
UserDomain := WshNetWork.UserDomain;
finally
WshNetWork := UnAssigned;
end;
ActiveUsers := TStringlist.Create;
try
HostInfo := EnumNetUsers(ActiveUsers);
for i := 1 to ActiveUsers.count - 1 do
begin
logIn := UserLoggedIn(ActiveUsers[i]);
result.add(format('Name: %s, last Login: %s', [ActiveUsers[i],logIn]));
end;
finally
ActiveUsers.Free;
end;
end;