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...!!!
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...!!!