Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Create list of computers

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2034
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Create list of computers
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Create list of computers - 2/10/2005 10:58:09 AM   
  yesbyes

 

Posts: 1
Score: 0
Joined: 2/10/2005
From:
Status: offline
I am new to this vbscript thing and I am looking for a script that will create a list of computers currently logged into the domain. Or just a list of computers that are on the same subnet as the computer running the script. This list can be stored in a variable for use later in the script or in a text file I can reference with vbscript. Any help would be GREAT!

_____________________________

I AM THE VBS-NEWBIE
 
 
Post #: 1
 
 Re: Create list of computers - 2/10/2005 1:12:13 PM   
  tnoonan

 

Posts: 364
Score: 0
Joined: 12/14/2004
From:
Status: offline
This script will give you a list of all pc's on domain that are powered on create a txt file and email you results:

'-------------------------------------------------------------------------------
' Initialization - Declare variables
'-------------------------------------------------------------------------------
Dim MyVar
Dim objOutlook
Dim objNameSpace
Dim mItem
Dim strCarbonCopy
Dim strBCC
Dim strReceipient
Dim strSubject
Dim strBodyText
Dim strMsg
Dim pAttachment
Dim strAttach
Dim DnameObj,objContainer,colPCs,objEnv,objDomain
Dim isnew,fso
dim message,dname
'Dim major,minor,ver,wshshell,key,key2
Dim fsoIn,fsoOut
Dim inFile,outFile,outExist,outExist2
Dim arrComputerNames
Dim objUser
Dim strComputer
Dim ErrorOccurred
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const inFilename = "PCList.txt"
Const outFileExist = "PCList.txt"
Const outFilename = "Online.txt"
Const outFileExist2 = "Online.txt"
Set WshShell = WScript.CreateObject("WScript.Shell")

'-------------------------------------------------------------------------------
'Get current Domain
'-------------------------------------------------------------------------------
key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon\CachePrimaryDomain"
dname = WshShell.RegRead (key)


set objEnv = WshShell.Environment("process")
dname = objEnv("USERDOMAIN")
on error resume next

'Bind to the builtin administrators group to see if you can connect
GetObject("WinNT://" & dname &"/administrators")
if err.number then
message = "Cannot bind to " &dname
WshShell.Popup message,0,"Connection or Authority Failure",vbCritical
WScript.Quit
End If

DnameObj = "WinNT://" & dname
WshShell.Popup "Please Stand By.....",3,"Query Domain",64
Set objContainer=GetObject(DnameObj)
objContainer.Filter=Array("computer")
Set fso = CreateObject("scripting.filesystemobject")

'-------------------------------------------------------------------------------
'List creation from active directory or User created ?
'-------------------------------------------------------------------------------

If (MsgBox("Do you want to create a list from active directory ? " &_
"", vbYesNo + vbQuestion,"www.spoogenet.com") = vbYes) Then
List

Else

message = message & "You need to type in you computer names and save file when completed"
WshShell.Popup message,0,"www.spoogenet.com",vbInformation
WshShell.Run "notepad PCList.txt"

End If

'-------------------------------------------------------------------------------
'If file exists delete and create from active directory
'-------------------------------------------------------------------------------
Sub List()
If (Not fso.FileExists(outFileExist)) Then
isnew = True
Else
isnew = False
End If

If isnew = False Then
fso.DeleteFile(outFileExist)
End If
Set outExist = fso.OpenTextFile(outFileExist, ForAppending, True)

For Each colPCs in objContainer
outExist.writeline colPCs.Name

Next

If (MsgBox("Done. All PCs in " & dname & " exported to " & outFileExist &_
". " & vbCrLf & "Open file " & outFileExist & " ?",_
vbYesNo + vbQuestion,"www.spoogenet.com") = vbYes) Then
WshShell.Run "notepad PCList.txt"

End If

If (Not fso.FileExists(outFileExist2)) Then
isnew = True
Else
isnew = False
End If

If isnew = False Then
fso.DeleteFile(outFileExist2)
End If
Set outExist2 = fso.OpenTextFile(outFileExist, ForAppending, True)

For Each colPCs in objContainer
outExist.writeline colPCs.Name

Next


End Sub

'-------------------------------------------------------------------------------
' Main script
'-------------------------------------------------------------------------------
On Error Resume Next
ErrorOccurred = False

' Open the input file
Set fsoIn = CreateObject("scripting.filesystemobject")
Set inFile = fsoIn.OpenTextFile(inFilename, ForReading, True)

' Open the log file (append mode) and timestamp the entry
Set fsoOut = CreateObject("scripting.filesystemobject")
Set outFile = fsoOut.OpenTextFile(outFilename, ForAppending, True)

While Not inFile.AtEndOfStream
arrComputerNames = Split(inFile.Readline, vbTab, -1, 1)
' arrComputerNames(0) contains the computer name
strComputer = arrComputerNames(0)

' Connect to the computer\administrator account
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator,user")
If Err.Number Then
Err.Clear
ErrorOccurred = True

(in reply to yesbyes)
 
 
Post #: 2
 
 Re: Create list of computers - 2/11/2005 11:56:35 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
I don't know if there is such thing as "computers" logged on to the domain, do you mean whether they are powered on or not ? If so, it can be done quickly by simply pinging them (assuming nothing blocks icmp ping request)

As for the PCs in the same subnet, it just requires a little bit of work (on top of the ping test) because you need to capture the IP for each PC and AND it with your own subnet mask, then compare that with the result of (your own IP AND your own subnet mask), if they are the same, then they are in the same subnet.

(in reply to yesbyes)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Create list of computers Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts