473,721 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use GetObject("winm gmts:\\" & StrComputer & "\root\cimv 2")

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("winm gmts:\\" & StrComputer & "\root\cimv 2")

returns a value System._ComObje ct 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("winm gmts:\\" & StrComputer &
"\root\cimv 2")

Dim ColItems As Object = ObjWMIService.E xecQuery("Selec t * from
Win32_Processor ")

For Each objItem As Object In ColItems

Console.WriteLi ne("L2 Cache Size: " & objItem.L2Cache Size)

Console.WriteLi ne("L2 Cache Speed: " & objItem.L2Cache Speed)

Console.WriteLi ne("Current Voltage: " & objItem.Current Voltage / 10.0)

Console.WriteLi ne("Maximum Clock Speed: " & objItem.current ClockSpeed)

Next
Feb 27 '07 #1
6 78404
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******** ******@TK2MSFTN GP04.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("winm gmts:\\" & StrComputer & "\root\cimv 2")

returns a value System._ComObje ct 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("winm gmts:\\" & StrComputer &
"\root\cimv 2")

Dim ColItems As Object = ObjWMIService.E xecQuery("Selec t * from
Win32_Processor ")

For Each objItem As Object In ColItems

Console.WriteLi ne("L2 Cache Size: " & objItem.L2Cache Size)

Console.WriteLi ne("L2 Cache Speed: " & objItem.L2Cache Speed)

Console.WriteLi ne("Current Voltage: " & objItem.Current Voltage / 10.0)

Console.WriteLi ne("Maximum Clock Speed: " & objItem.current ClockSpeed)

Next

Feb 27 '07 #2

" active" <ac********** @a-znet.comwrote in message
news:e1******** ******@TK2MSFTN GP04.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("winm gmts:\\" & StrComputer & "\root\cimv 2")

returns a value System._ComObje ct 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("winm gmts:\\" & StrComputer &
"\root\cimv 2")

Dim ColItems As Object = ObjWMIService.E xecQuery("Selec t * from
Win32_Processor ")

For Each objItem As Object In ColItems

Console.WriteLi ne("L2 Cache Size: " & objItem.L2Cache Size)

Console.WriteLi ne("L2 Cache Speed: " & objItem.L2Cache Speed)

Console.WriteLi ne("Current Voltage: " & objItem.Current Voltage / 10.0)

Console.WriteLi ne("Maximum Clock Speed: " & objItem.current ClockSpeed)

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.GetObje ctText_(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;
CreationClassNa me = "Win32_Processo r";
CurrentClockSpe ed = 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 = "GenuineInt el";
MaxClockSpeed = 2666;
Name = "Intel(R) Pentium(R) D CPU 2.66GHz";
NumberOfCores = 2;
NumberOfLogical Processors = 2;
PowerManagement Supported = FALSE;
ProcessorId = "BFEBFBFF00000F 47";
ProcessorType = 3;
Revision = 1031;
Role = "CPU";
SocketDesignati on = "";
Status = "OK";
StatusInfo = 3;
Stepping = "7";
SystemCreationC lassName = "Win32_Computer System";
SystemName = "DUALCORE";
UpgradeMethod = 1;
Version = "Model 4, Stepping 7";
};
"
Option Strict On
Imports WbemScripting
Imports System.Collecti ons

Module Module1
Sub Main()
Dim StrComputer As String = "."

Dim ObjWMIService As SWbemServicesEx =
DirectCast(GetO bject("winmgmts :\\" & StrComputer & "\root\cimv 2"),
SWbemServicesEx )

Dim ColItems As SWbemObjectSet = ObjWMIService.E xecQuery("Selec t *
from Win32_Processor ")

Dim en As IEnumerator = ColItems.GetEnu merator

Dim s As String
en.MoveNext()
While en.Current IsNot Nothing
Dim objItem As SWbemObjectEx
objItem = DirectCast(en.C urrent, SWbemObjectEx)
Dim t As String = objItem.GetObje ctText_(0)
'Console.WriteL ine("L2 Cache Size: " & objItem.L2Cache Size)

'Console.WriteL ine("L2 Cache Speed: " & objItem.L2Cache Speed)

'Console.WriteL ine("Current Voltage: " & objItem.Current Voltage
/ 10.0)

'Console.WriteL ine("Maximum Clock Speed: " &
objItem.current ClockSpeed)
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.Managem ent' ("System.Manage ment.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.WriteLi ne("L2 Cache Size: " & objItem.L2Cache Size)

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******** *************** ***********@mic rosoft.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******** ******@TK2MSFTN GP02.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.Managem ent' ("System.Manage ment.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.GetObje ctText_(0) is not late binding
but objItem.L2Cache Size is???
Dim t As String = objItem.GetObje ctText_(0)
'Console.WriteL ine("L2 Cache Size: " & objItem.L2Cache Size)
Thanks for the help
Feb 28 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
9471
by: Sammy | last post by:
Hi, my mind is going crazy. I have tried everything I can think of to no avail. I have tried Disable Output Escaping. I tried to think of a way of enclosing the attribute data in a CDATA element. That did not parse. Here is my question: How can I get attribute values to not get converted from &apos; to '
6
47433
by: Rich Wallace | last post by:
All, I receive an xml doc with an element which contains a &amp; in the data. I am attempting to insert the data into a SQL Server database and I want to convert the &amp; to a "&" character before I perform the insert. Is the a way in VB.NET to perform this? -Rich
11
6438
by: Jeremy | last post by:
How can one stop a browser from converting &amp; to & ? We have a textarea in our system wehre a user can type in some html code and have it saved to the database. When the data is retireved and
1
7717
by: Robert Dodier | last post by:
Hello, Sorry for asking what must be a FAQ, but I wasn't able to find the answer. I have an XML document fragment which I want to store as a text string. I want a function to convert any XML special characters such as < > into the corresponding character entities. I'm working with Java.
3
4458
by: gg | last post by:
I specify the Url element as <xsd:element name="Url"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:maxLength value="512"/> <xsd:pattern value="http://+"/> </xsd:restriction> </xsd:simpleType> </xsd:element> in the xsd but When I use the following in the xml
0
8852
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9081
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6676
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5992
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4761
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3206
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2590
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.