Else
objRecordSet.Requery
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
findUser = objRecordSet.Fields("AdsPath").Value
objRecordSet.MoveNext
Loop
End If
End Function
Function IsAlive(strComputer)
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select * from Win32_PingStatus where address = '"_
& strComputer& "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
IsAlive = "machine " & strComputer& " is not reachable"
Exit Function
Else
IsAlive = "Alive"
Exit Function
End If
Next
End Function
Sub ExcelHeaders()
'Create Excel Headers and color them in gray
Set objRange = objExcel.Range("A1","G1")
objRange.Font.Size = 12
objRange.Interior.ColorIndex=15
Sub FindCompUser(strComputer)
User = ""
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
User=objComputer.UserName
Next
User = Mid(User,4,intUser)
User = FindUser(User)
If Not User = 0 Then
Set objMember = GetObject(User)
strUser = objMember.Name
intUser = Len(strUser)
objExcel.cells(introw,1)= Mid(strUser,4,intUser)
objExcel.cells(introw,2)= objMember.givenname
objExcel.cells(introw,3)= objMember.sn
objExcel.cells(introw,4)= objMember.displayName
Else
objExcel.cells(introw,1)="No User"
End If
End Sub
' Opening File
Set objDialog = CreateObject("UserAccounts.CommonDialog")
If intResult = 0 Then
Wscript.Quit
Else
FileLoc = objDialog.FileName
End If
Set objExcel = CreateObject("Excel.Application")
Set objUsersExcel = CreateObject("Excel.Application")
Set objWorkbook = objUsersExcel.Workbooks.Open(FileLoc)
objExcel.Visible = True
objExcel.Workbooks.Add
introw=2
ExcelHeaders
Do Until objUsersExcel.Cells(intRow,1).Value = ""
Comp = objUsersExcel.Cells(introw,1)
objExcel.cells(introw,6)=IsAlive(Comp)
If IsAlive(Comp) = "Alive" Then
FindCompUser(Comp)
End If
objExcel.cells(introw,5)=Comp
introw=introw+1
Loop
'Auto Fit the Cells
set objRange = objExcel.Range("A1")
objRange.Activate
Set ObjRange = objExcel.ActiveCell.EntireColumn
objRange.AutoFit()
set objRange = objExcel.Range("B1")
objRange.Activate
Set ObjRange = objExcel.ActiveCell.EntireColumn
objRange.AutoFit()
set objRange = objExcel.Range("C1")
objRange.Activate
Set ObjRange = objExcel.ActiveCell.EntireColumn
objRange.AutoFit()
set objRange = objExcel.Range("D1")
objRange.Activate
Set ObjRange = objExcel.ActiveCell.EntireColumn
objRange.AutoFit()
set objRange = objExcel.Range("E1")
objRange.Activate
Set ObjRange = objExcel.ActiveCell.EntireColumn
objRange.AutoFit()
set objRange = objExcel.Range("F1")
objRange.Activate
Set ObjRange = objExcel.ActiveCell.EntireColumn
objRange.AutoFit()
set objRange = objExcel.Range("G1")
objRange.Activate
Set ObjRange = objExcel.ActiveCell.EntireColumn
objRange.AutoFit()
Set objWorkbook = objExcel.ActiveWorkbook
objWorkbook.SaveAs("C:\RemoteCompUsers.xls")
objExcel.Quit
objUsersExcel.Quit
wscript.Echo "OK" & vbClrf & "The File is Saved in C:\RemoteCompUsers.Xls"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.