General discussion
July 16, 2003 at 10:22 PM
kidrac

Problems with a vbs script

by kidrac . Updated 23 years, 3 months ago

Hi,

I have a small vbs script that was created to count the number of IO’s done on the system so far. The code is below:

On Error Resume Next

strClass= WScript.Arguments(0)
strNamespace = “root/cimv2”
strComputer = WScript.Arguments(1)
Set fileSys = CreateObject(“Scripting.FileSystemObject”)
Set ioOut = fileSys.CreateTextFile(“C:\ioStats.txt”)

Dim timeRun
Set colInstances = GetObject(“winmgmts:{impersonationLevel=impersonate}//” & _
strComputer & “/” & strNameSpace).InstancesOf(strClass)

ioOut.Write “IO Statistics for: ” & strComputer & vbcrlf
ioOut.Write “===============================================” & vbcrlf
timeRun = cdate(time())
For Each objInstance In colInstances
For Each objProperty In objInstance.Properties_
If objProperty.Name = “ReadOperationCount” Then
diskReads = diskReads+objProperty.Value
End if
If objProperty.Name = “WriteOperationCount” Then
diskWrites = diskWrites+objProperty.Value
End if
Next
Next
WScript.Echo timerun & “Total Reads: ” & diskReads & ” Total Writes: ” & diskWrites

The script does what it is supposed to do, but when I add upp the IO count, it concatenates the numbers instead of adding it, like this:

diskWrites = diskWrites+objProperty.Value

if diskWrites = 10 and objProperty.Value = 345 then I would expect diskWrites to end up = 355, but as it is now diskWrites ends up being = 10345. What am I doing wrong?

This discussion is locked

All Comments