469,649 Members | 1,209 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

How to use GetObject("winmgmts:\\" & StrComputer & "\root\cimv2")

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
Feb 27 '07 #1
6 76032
What you want to do is add a reference to Microsoft WMI Scripting V1.2
Library. It is added as a COM component thru the Add References.

You can then step thru without Strict On and get the object names you need.
Lloyd Sheen

" 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

Feb 27 '07 #2

" 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

Feb 27 '07 #3
"Lloyd Sheen" <a@b.cschrieb:
What you want to do is add a reference to Microsoft WMI Scripting V1.2
Library. It is added as a COM component thru the Add References.
Why not use 'System.Management' ("System.Management.dll"), which provides a
managed wrapper around WMI?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 27 '07 #4
For Each objItem As SWbemObjectEx In ColItems

Console.WriteLine("L2 Cache Size: " & objItem.L2CacheSize)

I still get the Object Strict disallows late binding for objItem

It must be possible to do this because if I set Option Strict Off

it works Ok

Thanks

"Lloyd Sheen" <a@b.cwrote in message
news:89**********************************@microsof t.com...
What you want to do is add a reference to Microsoft WMI Scripting V1.2
Library. It is added as a COM component thru the Add References.

You can then step thru without Strict On and get the object names you
need.
Lloyd Sheen

Feb 28 '07 #5
I tried to find L2 cache size in the docs about ManagementClass but there is
so much text. Probably if I had more familiarity I could find it. But so far
it eludes me.

Thanks

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uz**************@TK2MSFTNGP02.phx.gbl...
"Lloyd Sheen" <a@b.cschrieb:
>What you want to do is add a reference to Microsoft WMI Scripting V1.2
Library. It is added as a COM component thru the Add References.

Why not use 'System.Management' ("System.Management.dll"), which provides
a managed wrapper around WMI?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 28 '07 #6
Why is it objItem.GetObjectText_(0) is not late binding
but objItem.L2CacheSize is???
Dim t As String = objItem.GetObjectText_(0)
'Console.WriteLine("L2 Cache Size: " & objItem.L2CacheSize)
Thanks for the help
Feb 28 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Rich Wallace | last post: by
11 posts views Thread by Jeremy | last post: by
3 posts views Thread by gg | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.