Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > multiple conditions to check for

Reply
Thread Tools Display Modes

multiple conditions to check for

 
 
Dee
Guest
Posts: n/a

 
      07-21-2009

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
 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      07-21-2009

"Dee" <> wrote in message
news:EA926EE5-31DC-466B-9EB3-...
> 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


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.


 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      07-22-2009
Dee wrote:

>
> 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?
>


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


 
Reply With Quote
 
Dee
Guest
Posts: n/a

 
      07-22-2009

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\CI MV2")

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


"Richard Mueller [MVP]" wrote:

> Dee wrote:
>
> >
> > 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?
> >

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

 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      07-22-2009
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
--

"Dee" <> wrote in message
news:54DAEAD1-5F5E-436D-84A8-...
> 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\CI MV2")
>
> 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
>
>
> "Richard Mueller [MVP]" wrote:
>
>> Dee wrote:
>>
>> >
>> > 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?
>> >

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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to check if multiple workstations exists in AD from a TXT fil Zee Scripting 3 04-11-2008 10:02 PM
race conditions euacela@gmail.com Windows Vista Drivers 12 07-27-2007 03:28 AM
The Possible conditions to get STATUS_UNSUCCESSFUL when WdfUsbTargetDeviceSendControlTransferSynchronously is used. Neo Windows Vista Drivers 1 07-02-2007 10:23 AM
How to check if Networl is Bottleneck in multiple server? D.Bot Server Networking 1 01-15-2006 07:30 PM
check size of local and roaming profiles on multiple PCs Mike Windows Small Business Server 3 06-15-2005 06:16 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59