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

Re: Search files on remote computer by Torgeir

Torgeir
Fri Nov 26 16:22:09 CST 2004

Woef wrote:
> 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)
Hi

Using the FileSystemObject and access the admin share (\\computer\c$)
is an option...




--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: Search files on remote computer by Woef

Woef
Fri Nov 26 17:26:03 CST 2004

Ok. I adapted the code, and now it works.
Thx !

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 "\\whthuis\c$" 'Dosearch is the name of the function that
we'll use to search for files and subfolders.


"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:uItilaA1EHA.208@TK2MSFTNGP12.phx.gbl...
> Woef wrote:
>> 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)
> Hi
>
> Using the FileSystemObject and access the admin share (\\computer\c$)
> is an option...
>
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx