Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerating computer names in a domain (LAN)

Status
Not open for further replies.

FaneDuru

Technical User
Jul 15, 2002
141
RO
How is it possible to enumerate all computer names or user names logged on a domain in a local network using VBScript?

Thanks,
Fane
 
Hi you can do it by the script below. This will ask you for a domain and a path and filename for the log

'System variables - dont change
Dim TempFile, computer, domain, DomainSub, inputfile, outputfile
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForWriting = 2
Const ForReading = 1
Const ForAppending = 8
Const TristateFalse = 0


Set wshshell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")


Domain = inputbox ("Type Your Domain")
listdes = InputBox ("type destination for log")
if Domain = "" Then
MsgBox("Nothing Typed")
Else
Call GetDomain
Set infile = fso_OpenTextFile (listdes, ForReading, True) 'opens file for reading
Do While infile.AtEndOfStream <> True
If infile.AtEndOfStream <> True Then
strServername = Trim(infile.ReadLine)

End if
Loop



Sub GetDomain 'Gets a list of servers from the defined domain and writes to a file
Const TemporaryFolder = 2
Set TempFile = fso_OpenTextFile (listdes, ForWriting, True)
Set DomainObj = GetObject(&quot;WinNT://&quot; & domain)
For Each Object In DomainObj
If Object.class = &quot;Computer&quot; then
'WScript.Echo(Object.name)
TempFile.Writeline(Object.name)
Else
End If
whyme = Wscript.Echo(Object.Name)
Next
End Sub

End If
 
sorry remove the bit that says whyme = wscript.echo because that gives you the usernames and the other wscript command in there will bring up the box. Otherwise it should log all computer accounts on the domain to the file you specify
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top