[help] Wmi Vb Scripting

Hope somebody here can figure out what I'm doing wrong, I'm developing a few widgets and would like to include a usage monitor for my dsl connection, I've implemented the following function but all I get is 0?

The function is as follows:

Set objWMS = GetObject("winmgmts:\\.\root\cimv2")

'blah blah

Function NetLoad()

'On Error Resume Next

Dim Netitems, objNetinfo

WQLQuery = "Select * from Win32_PerfFormattedData_RemoteAccess_RASTotal"

Set Netitems = objWMS.ExecQuery(WQLQuery)

For Each objNetinfo in Netitems

NetLoad = objNetinfo.BytesReceivedPerSec

'WScript.Echo "NET Load is " & NETLoad

Next

'On Error goto 0

End Function

Anyone? :(

#184825

Originally posted by Tadis@Jul 2 2004, 01:26 AM

    WQLQuery = "Select * from Win32_PerfFormattedData_RemoteAccess_RASTotal"

Set Netitems = objWMS.ExecQuery(WQLQuery)

Whenever I execute this script on my machine, I get

0 for "NetItems.Count"

However it works with more trivial queries like Win32_DiskDrive.

My closest guess would be that this is a high performance counter, and would

not be up and running by default; look in your WMI documentation if you can

manually kick the perfmon object into its monitoring state.

Also note that RAS mostly means in this context that your machine is dialed in

from the outside telephone network but your DSL connection is of type outgoing.

Perhaps try "Win32_PerfRawData_Tcpip_NetworkInterface" or its formatted

counterpart if you are on XP - you may have multiple network connections

there and one of them should be your DSL...

hth,

herd

#185636

Thanks for the reply herd, but how would I go about 'manually kicking the perfmon object into its monitoring state' as you so eloquently put it? :lol: msdn isn't very helpful on this point and my old friend Mr Google has let me down yet again.

Also, regarding querying the network interface, the dsl connection doesn't show up, all I get is MS Loopback and another object "Slip...[something]" but neither is the correct value (in fct I'm not sure what these figures are for and how they relate to my connection :huh:

Any help would be greatly appreciated.

#186347

Well, this manual-kick business doesn't apply to you, I'd just verify by the

control panel in the services section if all WMI services are up and running.

DSL comes in many flavours:

- An USB modem

- An Ethernet hub, connected by a network card

- An Ethernet device, connected by a crossover network cable

- A PCMCIA card

depending on that, I'd look in my computers device manager, whether

my DSL is listed as a modem or a network adapter and try to locate

that specific hardware inside WMI. On my machine, the network adapter

does not show up by name since a generic driver is used and that would be

"NDIS 5.0".

Don't rely on the sparse docs but use Microsofts WMI Browser.

hth,

herd

#186376

did you tried browsing the categories using ms scriptomatic ?

very handy to see what will give results or not :

http://www.microsoft.com/downloads/details...a8-212c414a7ab0

Tho for monitoring a LAN connection (to your eth modem for example )

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_Tcpip_NetworkInterface",,48)
For Each objItem in colItems
   Wscript.Echo "BytesReceivedPersec: " & objItem.BytesReceivedPersec
   Wscript.Echo "BytesSentPersec: " & objItem.BytesSentPersec
   Wscript.Echo "BytesTotalPersec: " & objItem.BytesTotalPersec
   Wscript.Echo "Caption: " & objItem.Caption
   Wscript.Echo "CurrentBandwidth: " & objItem.CurrentBandwidth
   Wscript.Echo "Description: " & objItem.Description
   Wscript.Echo "Frequency_Object: " & objItem.Frequency_Object
   Wscript.Echo "Frequency_PerfTime: " & objItem.Frequency_PerfTime
   Wscript.Echo "Frequency_Sys100NS: " & objItem.Frequency_Sys100NS
   Wscript.Echo "Name: " & objItem.Name
   Wscript.Echo "OutputQueueLength: " & objItem.OutputQueueLength
   Wscript.Echo "PacketsOutboundDiscarded: " & objItem.PacketsOutboundDiscarded
   Wscript.Echo "PacketsOutboundErrors: " & objItem.PacketsOutboundErrors
   Wscript.Echo "PacketsPersec: " & objItem.PacketsPersec
   Wscript.Echo "PacketsReceivedDiscarded: " & objItem.PacketsReceivedDiscarded
   Wscript.Echo "PacketsReceivedErrors: " & objItem.PacketsReceivedErrors
   Wscript.Echo "PacketsReceivedNonUnicastPersec: " & objItem.PacketsReceivedNonUnicastPersec
   Wscript.Echo "PacketsReceivedPersec: " & objItem.PacketsReceivedPersec
   Wscript.Echo "PacketsReceivedUnicastPersec: " & objItem.PacketsReceivedUnicastPersec
   Wscript.Echo "PacketsReceivedUnknown: " & objItem.PacketsReceivedUnknown
   Wscript.Echo "PacketsSentNonUnicastPersec: " & objItem.PacketsSentNonUnicastPersec
   Wscript.Echo "PacketsSentPersec: " & objItem.PacketsSentPersec
   Wscript.Echo "PacketsSentUnicastPersec: " & objItem.PacketsSentUnicastPersec
   Wscript.Echo "Timestamp_Object: " & objItem.Timestamp_Object
   Wscript.Echo "Timestamp_PerfTime: " & objItem.Timestamp_PerfTime
   Wscript.Echo "Timestamp_Sys100NS: " & objItem.Timestamp_Sys100NS
Next

this will give you everything you need (or should)

#188124