3

I'm running some WMI queries against a remote computer (from JavaScript/JScript, WMIC, a downloaded WMI query tool -- it makes no difference), to which I have adminstrator privileges.

The query is against the Win32_Directory class and it attempts to find all folders on the target server, called 'db', 'hooks', 'conf' or 'locks', but it is not returning all folders; it only gets about 150 of them.

The queries I have tried are:

SELECT drive, path, filename 
FROM Win32_Directory 
WHERE filename = 'db' 
   OR filename = 'conf' 
   OR filename = 'hooks' 
   OR filename = 'locks'

and:

SELECT drive, path, filename 
FROM Win32_Directory 
WHERE name LIKE '%\\db' 
   OR name LIKE '%\\conf' 
   OR name LIKE '%\\locks' 
   OR name LIKE '%\\hooks'

or, in WMIC (from the local machine):

wmic fsdir where (name like '%\\db' or name like '%\\conf' or name like '%\\hooks' or name like '%\\locks') get drive,path,name

I'm pretty sure I've got my escaping sorted using \' and \\ where appropriate for JScript, and I'm using a basic call to var wmiResults = wmi.ExecQuery(wql, 'WQL', 32); to get the results set.

The equivalent batch command, run on the local machine returns far more results:

for /r %A in (db,conf,hooks,locks) do @if exist "%~A" echo %~A

It's like there's some sort of caching or paging going on, or an index needs rebuilding, but I don't know where to start to tell it to refresh its cache or retrieve all results.

Help!!

jimbobmcgee
  • 1,561
  • 11
  • 34
  • try adding the `Drive` field to the where part of the WQL sentence, something like `SELECT drive, path, filename FROM Win32_Directory WHERE Drive='C:' AND (name LIKE '%\\db' OR name LIKE '%\\conf' OR name LIKE '%\\locks' OR name LIKE '%\\hooks')` – RRUZ Oct 04 '11 at 02:28
  • Adding a drive clause didn't seem to make any difference but, then again, I added `WHERE drive LIKE '%:'` so it might have been optimised out... – jimbobmcgee Oct 11 '11 at 14:34
  • take a look at this: http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/554cefd3-f893-46de-9ba3-9dea045e4085 – Bizhan Dec 29 '11 at 09:49

0 Answers0