msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Finding PC names and adding them to spreadsheet

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax
Author Message
joeroc



Joined: 04 Oct 2007
Posts: 5

PostPosted: Thu Nov 30, 2006 3:56 pm    Post subject: Finding PC names and adding them to spreadsheet Reply with quote

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 spreadsheet. 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 spreadsheet. 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
spreadsheet. As of right now the script errors at the Sub
AddToSpreadSheet(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 AddToSpreadSheet(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 BuildSpreadsheet()
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
'Create a new workbook
oExcel.Workbooks.Add
'Bind to worksheet
Set oSheet = oExcel.ActiveWorkbook.Worksheets(1)
'Populate spreadsheet with info
oSheet.Cells(1, 1).Value = "Computer Name"
oSheet.Cells(1, 2).Value = "Groups"
'Format the spreadsheet
oSheet.Range("A1:A2").Font.Bold = True
oSheet.Select
oSheet.Range("B5").Select
oExcel.Columns(1).ColumnWidth = 20
oExcel.Columns(2).ColumnWidth = 20
'-------------------------------------------------------------------------
'------------------------------------------------------------------------
Sub AddToSpreadSheet(arrNetwork)
oExcel.Cells(intRow, 1).Value = arrNetwork(0)
intRow = intRow +1
oExcel.Cells(intRow, 1).Select
End sub

Archived from group: microsoft>public>vb>syntax
Back to top
View user's profile Send private message
Michael Cole



Joined: 04 Oct 2007
Posts: 79

PostPosted: Fri Dec 01, 2006 9:03 pm    Post subject: Re: Finding PC names and adding them to spreadsheet Reply with quote

joeroc wrote:
> I am new to vbscripting ...

microsoft.public.scripting.vb

VBScript is significantly different to VB, that the answers to questions are
not transferrable.


--
Regards,

Michael Cole
Back to top
View user's profile Send private message
joeroc



Joined: 04 Oct 2007
Posts: 5

PostPosted: Fri Dec 01, 2006 11:56 am    Post subject: Re: Finding PC names and adding them to spreadsheet Reply with quote

I'm not sure what you mean by that. The script i've posted is vbscript,
correct?

"Michael Cole" wrote:

> joeroc wrote:
> > I am new to vbscripting ...
>
> microsoft.public.scripting.vb
>
> VBScript is significantly different to VB, that the answers to questions are
> not transferrable.
>
>
> --
> Regards,
>
> Michael Cole
>
>
>
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 1325

PostPosted: Fri Dec 01, 2006 12:04 pm    Post subject: Re: Finding PC names and adding them to spreadsheet Reply with quote

"joeroc" wrote in message@microsoft.com
> I'm not sure what you mean by that. The script i've posted is
> vbscript, correct?

Yes, but this newsgroup is for the full VB language, not VBScript. They are
not quite the same thing.

>> microsoft.public.scripting.vb

is a newsgroup devoted to VBScript and a place where you are more likely to
get answers to your questions

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Back to top
View user's profile Send private message
Bob O`Bob



Joined: 04 Oct 2007
Posts: 1456

PostPosted: Fri Dec 01, 2006 10:17 pm    Post subject: Re: Finding PC names and adding them to spreadsheet Reply with quote

Bob Butler wrote:

>>> microsoft.public.scripting.vb
>
> is a newsgroup devoted to VBScript and a place where you are more likely to
> get answers to your questions
>


Not really.

But microsoft.public.scripting.vbscript
is.



Bob
--
Back to top
View user's profile Send private message
Bob Butler



Joined: 04 Oct 2007
Posts: 1325

PostPosted: Fri Dec 01, 2006 10:25 pm    Post subject: Re: Finding PC names and adding them to spreadsheet Reply with quote

"Bob O`Bob" wrote in message%23aFHHA.1188@TK2MSFTNGP06.phx.gbl
> Bob Butler wrote:
>
>>>> microsoft.public.scripting.vb
>>
>> is a newsgroup devoted to VBScript and a place where you are more
>> likely to get answers to your questions
>>
>
> Not really.
>
> But microsoft.public.scripting.vbscript
> is.

That's what I get for doing a copy & paste and not verifying it

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Back to top
View user's profile Send private message
Michael Cole



Joined: 04 Oct 2007
Posts: 79

PostPosted: Mon Dec 04, 2006 10:31 pm    Post subject: Re: Finding PC names and adding them to spreadsheet Reply with quote

Bob Butler wrote:
> "Bob O`Bob" wrote in message
> %23aFHHA.1188@TK2MSFTNGP06.phx.gbl
>> Bob Butler wrote:
>>
>>>>> microsoft.public.scripting.vb
>>>
>>> is a newsgroup devoted to VBScript and a place where you are more
>>> likely to get answers to your questions
>>>
>>
>> Not really.
>>
>> But microsoft.public.scripting.vbscript
>> is.
>
> That's what I get for doing a copy & paste and not verifying it

Mea culpa. I failed to check it.
Back to top
View user's profile Send private message
Rajneesh Noonia



Joined: 04 Oct 2007
Posts: 10

PostPosted: Mon Dec 04, 2006 7:17 am    Post subject: Re: Finding PC names and adding them to spreadsheet Reply with quote

Best way to generate code for your vb scripts is : Use excell macro
recording.

1.Create the file C:\NetViewList.txt by running hte commands manually.
2.Launch Excel and enable macro recording..
3.Do the data import and formating what ever you want (but without
errors)...
4.Stop recoring and view the macro code.

It is very much similar to vbscript...and you may easy translate it
back to vbscript..

Regards
Rajneesh

Michael Cole wrote:
> Bob Butler wrote:
> > "Bob O`Bob" wrote in message
> > %23aFHHA.1188@TK2MSFTNGP06.phx.gbl
> >> Bob Butler wrote:
> >>
> >>>>> microsoft.public.scripting.vb
> >>>
> >>> is a newsgroup devoted to VBScript and a place where you are more
> >>> likely to get answers to your questions
> >>>
> >>
> >> Not really.
> >>
> >> But microsoft.public.scripting.vbscript
> >> is.
> >
> > That's what I get for doing a copy & paste and not verifying it
>
> Mea culpa. I failed to check it.

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Finding a control's type I have a form that has a series of check boxes, each named chkErr1, chkErr2, chkErr3, etc. I want a command button to loop through each of the check boxes and perform an action if the checkbox is checked. I tried the following code: Dim thisCtl As Contr

How to add filed names in SQL? I've been able to query a table via a text box and bring in all the fields or a specific one by the 2 different flexvar statements. But I've been un-successful in putting a name for each column. I've tried as "xxxxx" but it only displays the data of that

Problem with finding substring Instr Hi, I use a variable to store the HTML text from a webpage. I wanted to find a substring in the HTML text using Instr function However, this doesn't work. I use foundPos0 = Instr(1, "tabledata", strHTML) and it always return zero. Is there something I am

VB screensaver file names I have written a screensaver, but I need to change the file name to an .exe and then to a .scr i think. I am unsure of how to do this... If anyone could give me some help to convert my screensaver into a file that can be recognized by the properties menu

Put column names into a flexgrid with SQL? I've been able to query a table via a text box and bring in all the fields or a specific one by the 2 different flexvar statements. But I've been un-successful in putting a name for each column. I've tried as "xxxx
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group