List last session of the users

1

I have this function that takes the last user that started session on a PC.

Function GetLastLogon

Dim LastLogonUser
Dim Count
Dim Final
Dim VFInal

LastLogonUser =objRegistry.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser")
Count=InStr(LastLogonUser,"\")
Final = Count + 1
VFInal=Mid(LastLogonUser,Final)
GetLastLogon = VFinal

End Function

I was wondering if there is any way to make a list of all the users that have accessed a single machine, because the function only shows the last user.

What occurred to me is the following, access the users folder and look there.

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.GetFolder("C:\Users")
set subfolder = objFile.subFolders
For each Name in subfolder 
   Wscript.Echo(Name)
next

Then he asks me if there is any other way to do it that we can access the users folder? I've been looking all morning but found.

    
asked by Kast 06.02.2018 в 11:45
source

1 answer

2

In the end what was found, I leave here the answer

Set objWMIService = GetObject("winmgmts:\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from  Win32_NetworkLoginProfile")

For Each objItem in colItems
Wscript.Echo objItem.Name
Next

This lists all the users of a machine.

    
answered by 06.02.2018 / 12:44
source