multiple conditions to check for

Discussion in 'Scripting' started by Dee, Jul 21, 2009.

  1. Dee

    Dee Guest


    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?


    Dee, Jul 21, 2009
    1. Advertisements

  2. 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.
    Pegasus [MVP], Jul 21, 2009
    1. Advertisements

  3. 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], Jul 22, 2009
  4. Dee

    Dee Guest

    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

    Dee, Jul 22, 2009
  5. 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 -

    Richard Mueller [MVP], Jul 22, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.