Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - how to obtain all pc in LAN and write to txtfile

Reply
 
Old 06-04-2009   #1 (permalink)


Vista Home Premium 32bit
 
 

how to obtain all pc in LAN and write to txtfile

hi guys, i want to get all pc in my land and write in my .txt file. using vbs

My System SpecsSystem Spec
Old 06-04-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: how to obtain all pc in LAN and write to txtfile


"webb" <guest@xxxxxx-email.com> wrote in message
news:458a725a42878d7da35962287018ae33@xxxxxx-gateway.com...
Quote:

>
> hi guys, i want to get all pc in my land and write in my .txt file.
> using vbs
>
>
> --
> webb
You can use ADO in a VBScript program to retrieve the names of all computer
objects in the domain. You can run the script below at a command prompt and
redirect the output to a text file:
==================
Option Explicit

Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strComputer

' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on computer objects.
strFilter = "(objectCategory=computer)"

' Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName"

' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

' Run the query.
Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values and display.
strComputer = adoRecordset.Fields("sAMAccountName").Value
' Remove trailing "$" character.
strComputer = Left(strComputer, Len(strComputer) - 1)
Wscript.Echo strComputer
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop

' Clean up.
adoRecordset.Close
adoConnection.Close

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
how to get powershell to write to event log or write a log file? PowerShell
Write-Error doesn't write anyting PowerShell
The disk is write-protected. Remove the write-protection or... Vista General
newline in Write-Debug or Write-Verbose PowerShell
Can't obtain IP Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46