Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Computer and Users Logged 3

Status
Not open for further replies.

cparralesl

Programmer
Jan 27, 2002
118
NI
Hello Guys,

I need to buid a Script that enumarate computers and users logged in a domain. I have tried to do it but I can only get the computer name; The user name logged is the only information missing.

Can someone help me with this?

Thanks Indvance.

Cesar Humberto Parrales
Application Support
 
Can you show me the code for obtaining the logged on computers. It is enough for me.

Thanks,
Fane Duru'
 
Ok Fane,

I have a vbs that make an excel report with Computer and users but, the information is taken from the server so that I am not sure if the users anumerated are logged.

The code that I used might not be the best, but it works out

Here is my code:

'Genera reporte de usuarios y grupos del dominio LAS
On Error Resume Next
Set dm = GetObject("WinNT://LAS,domain") 'Replace LAS by your domain Name.
Set a = CreateObject("Excel.Application")
Set b = a.Workbooks.Add

b.Application.Visible = True
a.Worksheets(1).name = "Usuarios"
a.Worksheets(1).cells(1,1).Value = "Nombre de cuenta"
a.Worksheets(1).cells(1,2).Value = "Nombre completo"
a.Worksheets(1).cells(1,3).Value = "Descripcion"
a.Worksheets(1).cells(1,4).Value = "Cuenta estatus"
a.Worksheets(1).cells(1,5).Value = "Clave expira"
a.Worksheets(1).cells(1,6).Value = "Correo e-mail"
a.Worksheets(1).cells(1,7).Value = "Grupos miembros"
a.Worksheets(1).Range("A1:G1").Font.Bold = True

a.Worksheets(2).name = "Grupos"

a.Worksheets(3).name = "Equipos"
a.Worksheets(3).cells(1,1).Value = "Nombre del Equipo"

Dm.Filter = Array("User")
I=2
For Each User in Dm
If User.IsAccountLocked Then
MsgEnll = "Cuenta está ENLLAVADA."
Else
MsgEnll = "Cuenta no enllavada."
End If
a.Worksheets(1).cells(I,1).Value = User.Name
a.Worksheets(1).cells(I,2).Value = User.FullName
a.Worksheets(1).cells(I,3).Value = User.Description
a.Worksheets(1).cells(I,4).Value = MsgEnll
a.Worksheets(1).cells(I,5).Value = User.PasswordExpirationDate
a.Worksheets(1).cells(I,6).Value = User.EmailAddress
Set G = GetObject("WinNT://LA/" & User.Name & ",user")
Set UG = G.Groups()
TtGrp = ""
For Each Group In UG
TtGrp = TtGrp + Group.Name & ", "
Next
a.Worksheets(1).cells(I,7).Value =Left(TtGrp,len(TtGrp)-2) & "."
I=I+1
Next
a.Worksheets(1).Range("A1:F1").EntireColumn.AutoFit

Dm.Filter = Array("Group")
C=1
For Each Group in Dm
F=1
a.Worksheets(2).cells(F,C).Value = Group.Name
F=F+1
For Each User in Group.Members
a.Worksheets(2).cells(F,C).Value = User.Name
F=F+1
Next
C=C+1
Next
a.Worksheets(2).Range("A1:E1").EntireColumn.AutoFit
a.Worksheets(2).Range(Selection, Selection.End(xlToRight)).Select
a.Worksheets(2).Selection.Font.Bold = True
[/c]

I hope this can help you.


Cesar Humberto Parrales
Application Support
 
Sorry, This is the last part of the script file. Paste it after the line

a.Worksheets(2).Selection.Font.Bold = True




Dm.Filter = Array("computer")
I=2
For Each computer in dm
a.Worksheets(3).cells(I,1).Value = computer.Name
a.Worksheets(3).cells(I,2).Value = computer.Status
a.Worksheets(3).cells(I,3).Value = computer.OperatingSystem
I=I+1
Next


Cesar Humberto Parrales
Application Support
 
Thanks, Humberto !
I try to use the network for sending URGENT messages using "Net Send". I made an Excel Addinn, which puts a button on the "Standard" CommandBar. Pressing it I load an array with the users logged on that day (I'd like to be sure that they are still logged but I'm not...)
For selecting between users the logged ones (most probable to be logged...) I use the "LastLogin" property of the collection:

Sub Sending()
Dim() DomainObj As Object(), Domeniu As String(), k As Long()
Dim() Nume As String(), NumeComplet As String(), Matrice(100, 3), Matr()
k = 0
Set DomainObj = GetObject("WinNT://icmrom")' your domain...
DomainObj.Filter = Array("user")
For Each UserObj In DomainObj
On Error Resume Next
If
Day(UserObj.LastLogin) = Day(Date) And _
Month(UserObj.LastLogin) = Month(Date) And _
Year(UserObj.LastLogin) = Year(Date) Then
If Err.Number <> 0 Then GoTo Continuare
Matrice(k, 1) = UserObj.Name: Matrice(k, 2) = UserObj.FullName
Matrice(k, 3) = UserObj.LastLogin: k = k + 1
End If
Continuare:
Next

'I wont to load in the form only the used array...
ReDim Matr(k, 3)
For i = 0 To k
For t = 1 To 3
Matr(i, t) = Matrice(i, t)
Next t
Next i
Trimitere_Mesaj.ListBox1.List() = Matr
Trimitere_Mesaj.Show
End Sub

'I use a form named &quot;Trimitere_Mesaj&quot;, having a listbox &quot;ListBox1&quot;, and a button. Here is the code:

Private Sub CommandButton1_Click()
Call Ales
Trimitere_Mesaj.Hide
End Sub

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Call Ales
End Sub

Sub Ales()
Dim Valoare
Valoare = ListBox1.Value
X = InputBox(&quot;What message do you wont to transmit to &quot; & Valoare & &quot; ?&quot;, &quot;Message to be sent !&quot;)
If X = &quot;&quot; Then MsgBox &quot;We'll stop !&quot;, , &quot;Stop of the program !&quot;: GoTo Sf
Shell (&quot;net send &quot; & Valoare & &quot; &quot; & X)
Sf:
End Sub

In this way I am able to select users which logged on in the day you are. I may miss the one which logged off, the one logged on since more then one day, etc. The AddInn works prity well but it isn't perfect. If you will find a way to catch only the logged on please, let me know (may be by mail ivangu@icme.vionet.gr ).

Thanks, anyhow,
Fane Duru'
 
Copied [thumbsup2]

Cesar Humberto Parrales
Application Support
 
Hi, Humberto,
I found a way to obtain the computers logged on at a specific moment. I use the &quot;Net view&quot; command:

Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set BT = fso_OpenTextFile(&quot;c:\Comp.bat&quot;, 2, True)
'Instead of &quot;icmrom&quot; you put your domain:
BT.Write &quot;net view /domain:icmrom > c:\computers.txt&quot;
'If you don't mention the domain will receive data for the domain where you are logged on (I commented the line...)
'BT.Write &quot;net view > c:\computers.txt&quot;
BT.Close
Set R = CreateObject(&quot;WScript.Shell&quot;)
x = R.Run(&quot;c:\Comp.bat&quot;, 0, True)

You may kill the bat file after that.
From the text file it's easy to take the computer names...
I didn't find a way to catch users......, yet.

I hope this help you.
Best regards,
Fane Duru'
 
Hi Fane,

Thanks for the tip. By the way, are you using Active Directory?

Cesar Humberto Parrales
Application Support
 

I'm not an network administrator. I try to obtain information regarding logged users (computers) like an ordinary user....
We don't use in our network Active Directory

Fane Duru'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top