/build/static/layout/Breadcrumb_cap_w.png

List users have been logged in our PC's

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?

0 Comments   [ + ] Show comments

Answers (3)

Answer Summary:
Posted by: aragorn.2003 8 years ago
Red Belt
1

Top Answer

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

ShellCommandTextReturn(cmd /c dir /B c:\users)

Comments:
  • Thank you very much. This is very simple and good procedure. - jitabares 8 years ago
Posted by: skc 8 years ago
Senior White Belt
0
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
   Next
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)
     Next
   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
   Else
     resolveSID = strDomain & "\" & strUser
   End If
End function

Comments:
  • 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. - jitabares 8 years ago
Posted by: anonymous_9363 8 years ago
Red Belt
0

> you must be know the name of the machine

See this line in the code:

strComputer = "computername"  'for local computer enter "."
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ