Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32_Directory query problem

Status
Not open for further replies.

josephk73

Technical User
Joined
Aug 1, 2002
Messages
115
Location
GB
Guys,

Can you please help with this...

This is the code...

strComputer = "xxxxx"
UserName = "administrator"
Password = "xxxxxxxx"
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",UserName,Password)
Set driveCol = objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)


First off I iterate through all HDD and add them to an array, but excluding C and Z

i = 0
For Each objvolname in driveCol
If objvolname.drivetype=3 and objvolname.caption <> "C:" and objvolname.caption <> "Z:" Then
arrOfDrives(i)= objvolname.caption
End if
i=i+1
Next


Next, I want to list all the folders (only folders!!) at the root of each drive found.

If I do this (hard code the drive letter into the query)

Set colDirectoryNum = objWMIService.ExecQuery("Select * from Win32_Directory where Drive = 'c:'")

for each foldername in colDirectoryNum
If (Instr(4,foldername.name,"\"))=0 Then
wscript.echo foldername.name
end if
Next

Things work.


However if use the array variable things dont work

Set colDirectoryNum = objWMIService.ExecQuery("Select * from Win32_Directory where Drive = 'arrofDrives(i)'")
for each foldername in colDirectoryNum
If (Instr(4,foldername.name,"\"))=0 Then
wscript.echo foldername.name
end if
Next

NADA.ZIP.ZERO.NOTHING


Just a heads up. If you echo out arrayofDrives(i), it CORRECTLY reports the drive letter. So it should work in the query.

Any ideas why?

Please...!!!
 
Try
Set colDirectoryNum = objWMIService.ExecQuery("Select * from Win32_Directory where Drive = '" & arrofDrives(i) & "'")
 
where are you dimming your arrofDrives? i dont see you dim it and i certainly dont see you redim'n as its size increases
 
guitarzan,

Yes you got it right. Thank you for taking the time to reply :-)

mrmovie thanks for your reply as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top