VBscript to audit machine info

Hi,

I need a VB script to interagate a list of computers in a text file , to see if the machine are on line, report the IP address , check for permission to C$, check if someone is logged in , the user of person logged in. all of above to be reported to a log file.

Many thanks,

garcoliAsked:
Who is Participating?
 
sirbountyCommented:
Looks like icacls is the winner.  If you have access to a Windows 2003 server, you should be able to grab it right out of the system32 folder (or simply run this script from there).
Const InputFile = "C:\Computers.txt"
Const OutputFile = "C:\ComputerAudit.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOut : Set objOut = objFSO.CreateTextFile (OutputFile)
Dim objShell : Set objShell = CreateObject("Wscript.Shell")
Dim objExec 

aryComputers = Split(objFSO.OpenTextFile(InputFile).ReadAll, vbNewLine)

For Each pc in aryComputers
  If Trim(pc) <> "" Then 
  wscript.echo "Querying " & pc & "..."
  objOut.WriteLine pc & " results..."
  PingResults = PingTest (pc)
  objOut.WriteLine vbTab & "Ping response: " & Split(PingResults,vbNewLine)(0) & vbTab & Split(PingResults, vbNewLine)(1) & vbTab
  objOut.WriteLine
  objOut.WriteLine vbTab & "C$ Perms:" & vbNewline & GetPermsOnC (pc)
  objOut.WriteLine
  arrSessions = SessionStatus (pc)
  If ubound(arrSessions) > 0 Then 
    objOut.WriteLine vbTab & "Sessions active:"
    for each strsession in arrSessions
      If Trim(strSession) <> "" Then objOut.WriteLine vbTab & vbTab & strSession
    next
  End If
  objout.WriteLine
  End If
Next
wscript.echo "Completed."
objOut.Close  

Function SessionStatus (strPC)
  Dim objConn : Set objConn = GetObject("WinNT://" & strPC & "/LanmanServer")
  Dim colSessions : Set colSessions = objConn.Sessions

  For Each objSession in colSessions
    arrSessionUsers = arrSessionUsers & vbNewLine & objSession.User
  Next
  arrSessionUsers = Split(arrSessionUsers, vbNewLine)
  If uBound(arrSessionUsers) < 1 Then
    ReDim arrSessionUsers(0)
    arrSessionUsers(0) = "No one"
  End If

  SessionStatus = arrSessionUsers
End Function 

Function GetPermsOnC (strPC)
  Dim strData
  Set objExec = objShell.Exec ("iCacls \\" & strPC & "\C$")
  strResults = lCase (objExec.StdOut.ReadAll)
  strResults = Replace(strResults, "\\" & strPC & "\c$", vbTab)
  For Each strLine in Split(strResults, vbNewLine)
    If strLine = "" Then Exit For
    strData = strData & vbTab & strLine & vbNewLine
  Next
  GetPermsOnC = strData
End Function

Function PingTest (strPC)
  If Trim(strPC) = "" Then
    PingTest = vbNewLine
    Exit Function
  End If
  Set objExec = objShell.Exec ("ping -n 2 -w 1000 " & strPC)
  blnOnline = False
  IP = "0.0.0.0"
  strResults = lCase(objExec.StdOut.ReadAll)
  If Instr(strResults, "reply from") Then blnOnline = True
  Set objExec = objShell.Exec ("nslookup " & strPC)
  strResults = lCase(objExec.StdOut.ReadAll)
  IP = Trim(Mid(strResults, InstrRev(strResults, "address")+8))
  PingTest = blnOnline & vbNewLine & IP
End Function

Open in new window

0
 
sirbountyCommented:
First portion should be easy enough (attached).
Need to know OS for some of the other stuff...?
Const InputFile = "C:\Computers.txt"
Const OutputFile = "C:\ComputerAudit.txt"

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOut : Set objOut = objFSO.CreateTextFile (OutputFile)
Dim objShell : Set objShell = CreateObject("Wscript.Shell")

aryComputers = Split(objFSO.OpenTextFile(InputFile).ReadAll, vbNewLine)

For Each pc in aryComputers
  PingResults = PingTest (pc)
  objOut.Write pc & vbTab & Split(PingResults,vbNewLine)(0) & vbTab & Split(PingResults, vbNewLine)(1) & vbTab
Next

objOut.Close  

Function PingTest (strPC)
  If Trim(strPC) = "" Then
    PingTest = vbNewLine
    Exit Function
  End If
  Dim objExec : Set objExec = objShell.Exec ("ping -n 2 -w 1000 " & strPC)
  blnOnline = False
  IP = "0.0.0.0"
  strResults = lCase(objExec.StdOut.ReadAll)
  If Instr(strResults, "reply from") Then blnOnline = True
  Set objExec = objShell.Exec ("nslookup " & strPC)
  strResults = lCase(objExec.StdOut.ReadAll)
  IP = Trim(Mid(strResults, InstrRev(strResults, "address")+8))
  PingTest = blnOnline & vbNewLine & IP
End Function

Open in new window

0
 
garcoliAuthor Commented:
OS is XP...thanks
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sirbountyCommented:
Are you opposed to some 3rd party (free) tools?
I believe one of the only ways of getting the remote perms is via cacls/icacls/xcacls, but I'm not having luck with the former (native) tool...  I believe xcacls/icacls may pull this...
0
 
garcoliAuthor Commented:
No that is fine.
0
 
garcoliAuthor Commented:
Hi,I am getting the following error in the attached document.

ScriptError.bmp
0
 
sirbountyCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.