" active" <ac**********@a-znet.comwrote in message
news:e1**************@TK2MSFTNGP04.phx.gbl...
This works with Strict Off
But not with Strict On
Sometimes I can figure out what is needed by running it and using
QuickWatch to see the type required but
GetObject("winmgmts:\\" & StrComputer & "\root\cimv2")
returns a value System._ComObject of Type Object
I don't know what to make of that.
Do you know how to fix this code?
thanks in advance
Dim StrComputer As String = "."
Dim ObjWMIService As Object = GetObject("winmgmts:\\" & StrComputer &
"\root\cimv2")
Dim ColItems As Object = ObjWMIService.ExecQuery("Select * from
Win32_Processor")
For Each objItem As Object In ColItems
Console.WriteLine("L2 Cache Size: " & objItem.L2CacheSize)
Console.WriteLine("L2 Cache Speed: " & objItem.L2CacheSpeed)
Console.WriteLine("Current Voltage: " & objItem.CurrentVoltage / 10.0)
Console.WriteLine("Maximum Clock Speed: " & objItem.currentClockSpeed)
Next
Ok what you need to do is add a COM reference to WbemScripting (Microsoft
WMI Scripting V1.2 Library) then your code would like something like:::
The string which is produced (Dim t As String = objItem.GetObjectText_(0))
gives a string like the following:
"
instance of Win32_Processor
{
AddressWidth = 32;
Architecture = 9;
Availability = 3;
Caption = "x64 Family 15 Model 4 Stepping 7";
CpuStatus = 1;
CreationClassName = "Win32_Processor";
CurrentClockSpeed = 2666;
CurrentVoltage = 30;
DataWidth = 64;
Description = "x64 Family 15 Model 4 Stepping 7";
DeviceID = "CPU0";
ExtClock = 133;
Family = 2;
L2CacheSize = 1024;
L2CacheSpeed = 2666;
L3CacheSize = 0;
L3CacheSpeed = 0;
Level = 15;
LoadPercentage = 13;
Manufacturer = "GenuineIntel";
MaxClockSpeed = 2666;
Name = "Intel(R) Pentium(R) D CPU 2.66GHz";
NumberOfCores = 2;
NumberOfLogicalProcessors = 2;
PowerManagementSupported = FALSE;
ProcessorId = "BFEBFBFF00000F47";
ProcessorType = 3;
Revision = 1031;
Role = "CPU";
SocketDesignation = "";
Status = "OK";
StatusInfo = 3;
Stepping = "7";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "DUALCORE";
UpgradeMethod = 1;
Version = "Model 4, Stepping 7";
};
"
Option Strict On
Imports WbemScripting
Imports System.Collections
Module Module1
Sub Main()
Dim StrComputer As String = "."
Dim ObjWMIService As SWbemServicesEx =
DirectCast(GetObject("winmgmts:\\" & StrComputer & "\root\cimv2"),
SWbemServicesEx)
Dim ColItems As SWbemObjectSet = ObjWMIService.ExecQuery("Select *
from Win32_Processor")
Dim en As IEnumerator = ColItems.GetEnumerator
Dim s As String
en.MoveNext()
While en.Current IsNot Nothing
Dim objItem As SWbemObjectEx
objItem = DirectCast(en.Current, SWbemObjectEx)
Dim t As String = objItem.GetObjectText_(0)
'Console.WriteLine("L2 Cache Size: " & objItem.L2CacheSize)
'Console.WriteLine("L2 Cache Speed: " & objItem.L2CacheSpeed)
'Console.WriteLine("Current Voltage: " & objItem.CurrentVoltage
/ 10.0)
'Console.WriteLine("Maximum Clock Speed: " &
objItem.currentClockSpeed)
en.MoveNext()
End While
End Sub
End Module