I would wanted to know how I make an script that list the users have been logged on in the PC's of my company. 
I thought the logical way is  dir / c: \ users>%COMPUTERNAME% > xxx.txt but I do not know how I can save it. We have no place shared by all. I would prefer that KACE show me a list/report with that information.  Would anybody know how to have that information?
Answer Summary:
0 Comments   [ + ] Show Comments


Please log in to comment

Answer Chosen by the Author

You can create a KACE custom field using this Custom Inventory Rule

ShellCommandTextReturn(cmd /c dir /B c:\users)
Answered 03/23/2016 by: aragorn.2003
Red Belt

  • This content is currently hidden from public view.
    Reason: Removed by member request
    For more information, visit our FAQ's.
  • Thank you very much. This is very simple and good procedure.
Please log in to comment


Try the below VBS......

Option explicit

' List Last logins on a client
'  also a remote WMI session to the computer and other
'  types of remote logon can be Registered User Logins too! )

Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, oReg, oWMISvc, regEx, dt

strComputer = "computername"  'for local computer enter "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")
Set oWMISvc = GetObject("winmgmts:\root\cimv2")
Set regEx = New RegExp
dt = now

call LastLogons(getLocalBIAS)

Sub LastLogons(lngBias)
   Dim strKeyPath, arrSubKeys, subkey, strValueName
   Dim sUsr, LastLogon, TimeHigh, TimeLow

   On Error Resume Next
   regEx.Pattern = "^S-1-5-21-[0-9]*-[0-9]*-[0-9]*-[0-9]*$"
   regEx.IgnoreCase = TRUE

   strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
   oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

   For Each subkey In arrSubKeys
     If regEx.Test(subkey)=TRUE Then
       sUsr = resolveSID(subkey)

       strValueName = "ProfileLoadTimeHigh"
       oReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath _
         & "\" & subkey, strValueName,TimeHigh

       strValueName = "ProfileLoadTimeLow"
       oReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath _
         & "\" & subkey, strValueName,TimeLow

       LastLogon = getDT(TimeHigh, TimeLow, lngBias)

       If sUsr = Empty Then
         strValueName = "ProfileImagePath"
         oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE, strKeyPath _
           & "\" & subkey, strValueName,sUsr
       End If

       ' last 24 hours only,
   rem    If DateDiff("n",LastLogon, dt)/60 =< 24 Then

       ' one particular user only,
   rem    If InStr(1,sUsr,"Igor",1) Then

         MsgBox sUsr & vbNewline _
           & "LastLogon: " & LastLogon, _
           ,"Computer: " & strComputer

   rem    End If
   rem    End If

     End If
End Sub

Function getLocalBIAS
   ' Obtain local Time Zone bias from machine registry.
   ' (= the time-zone + daylight saving offset)
   ' This bias changes with Daylight Savings Time.
   Dim strKeyPath, strValueName, lngBiasKey

   strKeyPath = "System\CurrentControlSet\Control\TimeZoneInformation"
   strValueName = "ActiveTimeBias"
   oReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName,lngBiasKey
   If (UCase(TypeName(lngBiasKey)) = "LONG") Then
     getLocalBIAS = lngBiasKey
   ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then
     getLocalBIAS = -0
     For k = 0 To UBound(lngBiasKey)
       getLocalBIAS = getLocalBIAS + (lngBiasKey(k) * 256^k)
   End If
End Function

Function getDT(H, L, Bias)
   ' http://forums.petri.com/showpost.php?p=182526&postcount=2
   On Error Resume Next

   Dim HexVal, Highpart, Lowpart, lngDate

   'HexVal = H
   'HexVal = Replace(HexVal, "0x", "")
   'HexVal = Replace(HexVal, "&H", "")
   'Highpart = CLng("&H" & HexVal)
   Highpart = H ' 

   'HexVal = L
   'HexVal = Replace(HexVal, "0x", "")
   'HexVal = Replace(HexVal, "&H", "")
   'Lowpart = CLng("&H" & HexVal)
   Lowpart = L

   '# unite the HighPart and LowPart
   lngDate = Highpart * 2^32 + L

   '# convert the number of 100-Nanosecond intervals to days
   lngDate = ((lngDate*1E-7/60) -Bias)/1440  'days

   '# Add the number of days to the "zero" date
   getDT = CDate( #1/1/1601# + lngDate )
End Function

Function resolveSID(sid)
   Dim strUser, strDomain
   On Error Resume Next
   With oWMISvc
With .Get("Win32_SID.SID='" & sid & "'")
  strUser = .AccountName
  strDomain = .ReferencedDomainName
End With
End With
   If len(strUser) = 0 Then
     resolveSID = Empty
     resolveSID = strDomain & "\" & strUser
   End If
End function
Answered 03/22/2016 by: skc
Senior White Belt

  • Thank you.
    This proposal is valid but you must be know the name of the machine.
    I need to launch a script that provides me a relationship between the machine and users who are logged on to that machine.
Please log in to comment

> you must be know the name of the machine

See this line in the code:

strComputer = "computername"  'for local computer enter "."
Answered 03/23/2016 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity