Discussion:
multiple conditions to check for
(too old to reply)
Dee
2009-07-21 16:11:01 UTC
Permalink
Hi

I want to check multiple objects, but not sure how to add them to the vb
script code

VB CODE:
if objItem.Name = "C:" then

I want to check C drive and D drive for space and the above line works ok,
however I want to also check the D drive, but need to know how to add that to
the same line, any thoughts?


Rgds

D
--
Dee
Pegasus [MVP]
2009-07-21 17:16:43 UTC
Permalink
Post by Dee
Hi
I want to check multiple objects, but not sure how to add them to the vb
script code
if objItem.Name = "C:" then
I want to check C drive and D drive for space and the above line works ok,
however I want to also check the D drive, but need to know how to add that to
the same line, any thoughts?
Rgds
D
Please post a more meaningful code fragment than the one above so that we
can see what you're trying to do and how far you got so far.
Richard Mueller [MVP]
2009-07-22 00:11:51 UTC
Permalink
Post by Dee
I want to check multiple objects, but not sure how to add them to the vb
script code
if objItem.Name = "C:" then
I want to check C drive and D drive for space and the above line works ok,
however I want to also check the D drive, but need to know how to add that to
the same line, any thoughts?
In general, conditions can be combined in If/Then statements using "And",
"Or", and "Not" logical operators. For example:

If (objItem.Name = "C:") Or (objItem.Name = "D:") Then
' Statements that run only if name is "C:" or "D:"...
End If

As noted, we may need to see more of your code, or understand what you are
trying to do. It might make sense to check space on C: and D: separately.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Dee
2009-07-22 08:18:01 UTC
Permalink
Hi guys sorry not to have put more of the code and thansk Richard, you
suggestion works.

Here is the code:


Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer(strComputer,"root\CIMV2")

Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_LogicalDisk",,48)
For Each objItem in colItems
if (objItem.Name = "C:") Or (objItem.Name = "D:") then
Freespace = objItem.FreeSpace
'Wscript.Echo "-----------------------------------"
'Wscript.Echo "Win32_LogicalDisk instance"
'Wscript.Echo "-----------------------------------"
Wscript.Echo "Disk Drive: " & objItem.Name
'Wscript.Echo "FreeSpace: " & objItem.FreeSpace
'Wscript.Echo "Size: " & objItem.Size
Wscript.Echo "FreeSpace is : " & Int(Freespace / 1073741824) & " GB"
end if



Cheers!
--
Dee
Post by Richard Mueller [MVP]
Post by Dee
I want to check multiple objects, but not sure how to add them to the vb
script code
if objItem.Name = "C:" then
I want to check C drive and D drive for space and the above line works ok,
however I want to also check the D drive, but need to know how to add that to
the same line, any thoughts?
In general, conditions can be combined in If/Then statements using "And",
If (objItem.Name = "C:") Or (objItem.Name = "D:") Then
' Statements that run only if name is "C:" or "D:"...
End If
As noted, we may need to see more of your code, or understand what you are
trying to do. It might make sense to check space on C: and D: separately.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Richard Mueller [MVP]
2009-07-22 16:02:11 UTC
Permalink
Your code works fine for me, after I add a "Next" statement at the end, and
assign a value to strComputer.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Post by Dee
Hi guys sorry not to have put more of the code and thansk Richard, you
suggestion works.
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService =
objSWbemLocator.ConnectServer(strComputer,"root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_LogicalDisk",,48)
For Each objItem in colItems
if (objItem.Name = "C:") Or (objItem.Name = "D:") then
Freespace = objItem.FreeSpace
'Wscript.Echo "-----------------------------------"
'Wscript.Echo "Win32_LogicalDisk instance"
'Wscript.Echo "-----------------------------------"
Wscript.Echo "Disk Drive: " & objItem.Name
'Wscript.Echo "FreeSpace: " & objItem.FreeSpace
'Wscript.Echo "Size: " & objItem.Size
Wscript.Echo "FreeSpace is : " & Int(Freespace / 1073741824) & " GB"
end if
Cheers!
--
Dee
Post by Richard Mueller [MVP]
Post by Dee
I want to check multiple objects, but not sure how to add them to the vb
script code
if objItem.Name = "C:" then
I want to check C drive and D drive for space and the above line works ok,
however I want to also check the D drive, but need to know how to add
that
to
the same line, any thoughts?
In general, conditions can be combined in If/Then statements using "And",
If (objItem.Name = "C:") Or (objItem.Name = "D:") Then
' Statements that run only if name is "C:" or "D:"...
End If
As noted, we may need to see more of your code, or understand what you are
trying to do. It might make sense to check space on C: and D: separately.
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Loading...