Hi all,
I want to search on multiple remote computers (nt 4 & XP) for *.wab files.
Because the NT-machines, I can't use WMI.
Is there another way to do this ?
I add 2 scripts that I use now. 1 for a local machine (systemfileobject)
and 1 for remote machines (WMI)
Thank you all.
Greetz
Wim Heirbaut.
'********************************************************
'*
'* Search adressbooks (*.wab) in Active Directory Computers, via
FILESYSTEMOBJECT
'* How to do this on several remote computers ?
'*
'********************************************************
On error resume next
Dim Fso, Drives, Drive, Folder, Files, File, Subfolders,Subfolder 'First
of all, you have declare the variables and create the FileSystem object.
Dim strComputer
Set Fso=createobject("scripting.filesystemobject") 'Then, Set the Drives
object, so you can search in all the available drives of the computer
Set Drives=fso.drives
Dosearch "c:\" 'Dosearch is the name of the function that we'll use
to search for files and subfolders.
Function Dosearch(Path)
Set Folder=fso.getfolder(path) 'Get the folder where we have to work.
Set Files = folder.files 'Get all the files inside this folder
For Each File in files 'File is the current file where we are 'Now do a
for-each for each file
If fso.GetExtensionName(file.path)="wab" then
msgbox file.path 'Just to do something
end If
Next
Set Subfolders = folder.SubFolders 'Get all subfolders in our main
folder
For Each Subfolder in Subfolders 'Now, for each subfolder
Dosearch Subfolder.path
Next
end function
wscript.echo "Gedaan"
********************************
*******************************
***************************
'*********************************************
'*
'* Search adressbooks in Active Directory computers, via WMI
'* If there is a computer not powered on, the script ends unexpected :-(
'*
'**********************************************
on error resume next
Dim objDSE, strDefaultDN, strDN, objContainer, objChild
'***************************
' Create Excel File
'***************************
Set objExcel = WScript.CreateObject("Excel.Application") 'Create Excell
file
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.ActiveSheet.Name = "Adresbooks"
objExcel.ActiveSheet.Range("A1").Activate
objExcel.ActiveCell.Value = "PC" 'col header 1
objExcel.ActiveCell.Offset(0,1).Value = "Location 1" 'col header 2
objExcel.ActiveCell.Offset(0,2).Value = "Location 2" 'col header 3
objExcel.ActiveCell.Offset(0,3).Value = "Location 4" 'col header 2
objExcel.ActiveCell.Offset(0,4).Value = "Location 5" 'col header 2
objExcel.ActiveCell.Offset(1,0).Activate 'move 1 row down
'***************************
' Run through Active directory
' searching for computers
'***************************
Set objDSE = GetObject("LDAP://rootDSE")
strDefaultDN = objDSE.Get("defaultNamingContext")
strDN = InputBox("Enter the distinguished name of a container" & vbCrLf &
"(e.g. " & strDefaultDN & ")", , strDefaultDN)
If strDN = "" Then WScript.Quit(1) 'user clicked Cancel
Set objContainer = GetObject("LDAP://" & strDN)
Call ListUsers(objContainer)
objExcel.close
wscript.echo "Script finished"
Sub ListUsers(objADObject)
Dim objChild
For Each objChild in objADObject
Select Case objChild.Class
Case "computer"
strComputer=objChild.cn
AdresboekZoeken(strComputer) 'search adressbook
Case "organizationalUnit" , "container"
Call ListUsers(objChild)
End select
Next
End Sub
'****************************************
'Search adressbook on remote computer
'****************************************
Sub AdresboekZoeken(Computer)
teller=0
WScript.Echo "I start search on : " & Computer
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2") ' maakt
verbinding met wmi van computer
Set colDisks = objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk
WHERE Name = 'C:'")
For Each objDisk in colDisks
Set colFiles = objWMIService.ExecQuery ("SELECT * FROM CIM_DataFile
WHERE Drive = 'C:'")
For Each objFile in colFiles
If objFile.Extension= "wab" then
Wscript.Echo Computer & " ==> " & objFile.Name
objExcel.ActiveCell.Value = computer
objExcel.ActiveCell.Offset(0,1+teller).Value = objFile.Name
teller=teller+1
End If
Next
Next
wscript.echo "Finished searching on pc " & computer
End Sub