Finding PC names and adding them to spread***
- From: joeroc <joeroc@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 30 Nov 2006 10:56:01 -0800
I am new to vbscripting and am trying to come up with a script that uses the
net view command to determine PC names on the network and then take those
names and populate a spread***. I've taken almost all of the following
code from another script i've found on the net but am unable to make it work
completely. The Net View part works but i'm unable to parse the info and
then popluate a spread***. Would someone be able to help with this. My
ultimate goal is to then use those PC names and to detemine what groups\users
are part of the local admin group and write that info to the same
spread***. As of right now the script errors at the Sub
AddToSpread***(arrNetwork) which located toward the botom.
Const FOR_READING = 1 'Used to open and read a file
Set oShell = CreateObject("wscript.shell")
Set oFso = CreateObject("scripting.filesystemobject")
Set oXL = Wscript.CreateObject("Excel.Application")
Set oRegularExpression = New RegExp
'Start to write at row 2 of excel file
introw = 2
'Runs command prompt Net View and writes output to NetViewList.txt file
oShell.Run "cmd.exe /c net view > c:\NetViewList.txt" , 2, True
'Open NetViewList.txt file
Set oNetViewList = oFSO.OpenTextFile("C:\NetViewList.txt", FOR_READING, True)
'Loop through NetViewList.txt file
Do While oNetViewList.AtEndOfStream <> True
Redim arrNetwork(0)
strCurrentLine = oNetViewList.Readline
strPattern = "\\"
'Test to find strPattern in strCurrentline
bInPatternFound = GetPattern(strCurrentLine, strPattern)
'If True Proceed...
If bInPatternFound Then
strPattern = "\\\\\S*"
intFlag = 1
' find hostname in file
arrNetwork(0) = GetMatch(strCurrentLine, strPattern, intFlag)
strHostName = arrNetwork(0)
End If
Loop
Call AddToSpread***(arrNetwork)
'----------------------------------------------------------------------
'----------------------------------------------------------------------
Function GetMatch(strSource, strSourcePattern, intflag)
Dim strMatch
Dim strIsMatch
'affect pattern to RegExp.Pattern
oRegularExpression.Pattern = strSourcePattern
'executes a search for a match (pattern) in the specified string
'returng a result array
Set oMatches = oRegularExpression.Execute(strSource)
For Each strMatch In oMatches
strIsMatch = strMatch.Value
'1 is matching hostname
If intFlag = 1 Then strIsMatch = Mid(strIsMatch,3)
'End If
Next
GetMatch = strIsMatch
Set oMatches = Nothing
End Function
'----------------------------------------------------------------------
'----------------------------------------------------------------------
Function GetPattern(strSource, strSourcePattern)
'Give the pattern to RegExp to test source which is strCurrentLine
oRegularExpression.Pattern = strSourcePattern
'Test for a match of a regualr expression (Pattern) in the string
'returning true is successful and false if not
If oRegularExpression.Test(strSource) Then
GetPattern = "True"
Else
GetPattern = "False"
End If
End Function
'------------------------------------------------------------------------
'------------------------------------------------------------------------
Sub BuildSpread***()
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
'Create a new workbook
oExcel.Workbooks.Add
'Bind to work***
Set oSheet = oExcel.ActiveWorkbook.Worksheets(1)
'Populate spread*** with info
o***.Cells(1, 1).Value = "Computer Name"
o***.Cells(1, 2).Value = "Groups"
'Format the spread***
o***.Range("A1:A2").Font.Bold = True
o***.Select
o***.Range("B5").Select
oExcel.Columns(1).ColumnWidth = 20
oExcel.Columns(2).ColumnWidth = 20
'-------------------------------------------------------------------------
'------------------------------------------------------------------------
Sub AddToSpread***(arrNetwork)
oExcel.Cells(intRow, 1).Value = arrNetwork(0)
intRow = intRow +1
oExcel.Cells(intRow, 1).Select
End sub
.
- Follow-Ups:
- Re: Finding PC names and adding them to spread***
- From: Michael Cole
- Re: Finding PC names and adding them to spread***
- Prev by Date: Re: MaskedEdit
- Next by Date: Save settings to file
- Previous by thread: Re: MaskedEdit
- Next by thread: Re: Finding PC names and adding them to spread***
- Index(es):