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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

garcoliAuthor Commented:
No that is fine.
0
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
garcoliAuthor Commented:
Hi,I am getting the following error in the attached document.

ScriptError.bmp
0
sirbountyCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.