Do While...Loop

上一篇 / 下一篇  2010-03-23 14:14:43 / 个人分类:VBScript

Do While...Loop

The Do While...Loop command enables you to run a script. as long as a certain condition is in effect

 

Example:MonitorForChangedDiskSpace.vbs

'Header information section,define the variabl and on error resume Next
Option Explicit
On Error Resume Next
Dim colMonitoredDisks
Dim objWMIService
Dim objDiskChange
Dim strComputer
Dim startTime 'snapTime used for timer Function

'reference information secton
Const LOCAL_HARD_DISK = 3 'the driveType value from SDK
Const RUN_TIME = 1000 'time to allow the script. to run in seconds
strComputer = "."
startTime = Timer

'Worker and Output Information section
Set bjWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredDisks = objWMIService.ExecNotificationQuery _
   ("Select * from __instancemodificationevent within 10 where " _
     & "TargetInstance ISA 'Win32_LogicalDisk'")
Do While True
snapTime = Timer
 Set bjDiskChange = colMonitoredDisks.NextEvent
  If objDiskChange.TargetInstance.DriveType = LOCAL_HARD_DISK Then
  WScript.echo "diskSpace on " &_
  objDiskChange.TargetInstance.deviceID &_
  " has changed. It now has " &_

  objDiskChange.TargetInstance.freespace &_
  " Bytes free."
  End If
  If (snapTime - startTime) > RUN_TIME Then
  Exit Do
  End If
Loop
WScript.Echo FormatNumber(snapTime-startTime) & " seconds elapsed. Exiting now"
WScript.quit

 

 

From
Microsoft® VBScript. Step by Step
By Ed Wilson

 

 


TAG:

 

评分:0

我来说两句

Open Toolbar