WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: jpaton on August 27, 2013, 07:09:43 AM

Title: Search domain workstations for file existence
Post by: jpaton on August 27, 2013, 07:09:43 AM
Does anyone know of a way to search all active workstations in a windows domain for a file existence?
Title: Re: Search domain workstations for file existence
Post by: Deana on August 27, 2013, 09:46:31 AM
No single function to handle this. I suspect you would need to get a list of all the computers in the domain then search tem individually. What kind of access do you have to all the computers in the domain? Via Windows Share or FTP?
Title: Re: Search domain workstations for file existence
Post by: jpaton on August 27, 2013, 11:07:30 AM
I have full access to all the computers using the windows share (c$).
Title: Re: Search domain workstations for file existence
Post by: Deana on August 27, 2013, 11:36:10 AM
To get started you will need to get a list of Servers. This can be accomplished using the Win32 Network Extender function wntResources2 or the using ADSI extender:

Code (winbatch) Select

;List all servers in the current Domain
;Load Appropriate Extender
AddExtender("WWADS44I.DLL",0,"WWADS64I.DLL")

; Construct the full domain ADSI path.
ServerDn = dsGetProperty("LDAP://rootDSE", "serverName")
ServerName = ItemExtract(1, ServerDn, ",")
ServerName = ItemExtract(2, ServerName, "=")
ServerDn = dsGetProperty("LDAP://rootDSE", "defaultNamingContext")
ServerPath = "LDAP://%ServerName%/%ServerDN%"
sFilter = `(objectCategory=computer)`

MyOuPaths = dsFindPath(ServerPath, sFilter)
oucount = ItemCount(myoupaths,@TAB)
serverlist = ''
For x = 1 To oucount
   ou = ItemExtract(x,myoupaths,@TAB)
   objServer = ObjectGet(ou)
   cn = objServer.CN
   if serverlist == '' then  serverlist = '\\': cn :'\C$'
else serverlist = serverlist : @TAB : '\\': cn :'\C$'
   objServer = 0
Next
AskItemlist( 'Server list', StrTrim( serverlist ), @TAB, @UNSORTED, @SINGLE )
Exit


Now that you have a list of servers you can search each on for a file using the File Search Extender.
Title: Re: Search domain workstations for file existence
Post by: td on August 27, 2013, 01:11:40 PM
If you are just checking file existence and not also checking file contents, it would be best to use the File and Folder Finder extender instead of the Search extender.  The FAF extender can handle long paths+filenames, were as the Search extender is limited to MAXPATH.