' ---------------------------------------------------------- ' Script affichant les sessions actuellement ouvertes ' ainsi que les dates des dernières connexions locales ' sur un ordinateur local ou distant ' ' Syntaxe: ' sessions [nom_de_machine] ' ' si "nom_de_machine" est omis => machine locale ' ' JC BELLAMY © 2002 ' ---------------------------------------------------------- Dim network, server,args, ComputerSystem Set network =Wscript.CreateObject("WScript.Network") Set args=Wscript.Arguments nbargs=args.count If nbargs>0 Then Machine = args(0) Else Machine = network.ComputerName 'Récupération du nom de domaine ou Workgroup Set ComputerSystem = GetObject("winmgmts://" & Machine).InstancesOf("Win32_ComputerSystem") For each System in ComputerSystem Domaine = System.Domain Next mess="Ordinateur " & machine & " (domaine/workgroup """ & Domaine & """) :" & vbcrlf & vbcrlf Set Server = GetObject("WinNT://" & Domaine & "/" & Machine & "/LanManServer") n=0 result="" For each Session in Server.Sessions n=n+1 user=Session.user If len(user)>0 Then temps=session.connecttime h=int(temps/3600) mn=int((temps - h*3600)/60) result= result & user & " depuis " & Session.Computer & " (durée : " & h & "h " & mn & "mn)" & VBCRLF End If Next If n>1 Then suffixe="s" else suffixe="" mess=mess & "--- " & n & " session" & suffixe & " actuellement ouverte" & suffixe & " : " & vbcrlf mess=mess & result & vbcrlf mess=mess & "--- Dates des dernières connexions locales :" & vbcrlf result="" Dim LoginProfiles, Profile Set LoginProfiles = GetObject("winmgmts://" & Machine).InstancesOf("Win32_NetworkLoginProfile") for each Profile in LoginProfiles account=Profile.Name p=instr(account,"\") If p>1 Then If lcase(left(account,p-1))=lcase(Machine) Then strlogon=analyse(Profile.LastLogon) result=result & strlogon & " : " & mid(account,p+1) & vbcrlf End If End If next mess=mess & result wscript.echo mess ' ------------------------------------- Function analyse(ch) a=mid(ch,1,4) m=mid(ch,5,2) j=mid(ch,7,2) h=mid(ch,9,2) mn=mid(ch,11,2) s=mid(ch,13,2) analyse=j & "/" & m & "/" & a & " " & h & ":" & mn & ":" & s End Function ' -------------------------------------