Is using System.Manageme nt in general a faux pas? It seems, after some
web searching, that there is a fair amount of resistance to it because
of speed and portability.
I need to know how many CPU sockets there are. I'm using
System.Manageme nt to do this. It takes about two seconds to do this.
(Which, yes, is full-on crap for speed.) But what is the better way to
determine the number of CPU sockets in Windows version >= 5 with
a .NET >= 2.0 application? 12 2394
not_a_commie,
With the System.Manageme nt namespace, you are trading off performance
for ease-of-use, and maintainability (through a unified object model and
query syntax). I am sure that there is much faster code to find this out,
but it is most likely done with interop, which if not done correctly, can
impact ease-of-use and maintainability .
So in the end, it is a trade off, and like all trade offs, you have to
make the decision which one is better for your application's needs.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"not_a_comm ie" <no********@gma il.comwrote in message
news:11******** *************@d 30g2000prg.goog legroups.com...
Is using System.Manageme nt in general a faux pas? It seems, after some
web searching, that there is a fair amount of resistance to it because
of speed and portability.
I need to know how many CPU sockets there are. I'm using
System.Manageme nt to do this. It takes about two seconds to do this.
(Which, yes, is full-on crap for speed.) But what is the better way to
determine the number of CPU sockets in Windows version >= 5 with
a .NET >= 2.0 application?
"not_a_comm ie" <no********@gma il.comwrote in message
news:11******** *************@d 30g2000prg.goog legroups.com...
Is using System.Manageme nt in general a faux pas? It seems, after some
web searching, that there is a fair amount of resistance to it because
of speed and portability.
I need to know how many CPU sockets there are. I'm using
System.Manageme nt to do this. It takes about two seconds to do this.
(Which, yes, is full-on crap for speed.) But what is the better way to
determine the number of CPU sockets in Windows version >= 5 with
a .NET >= 2.0 application?
Environment.Pro cessorCount, returns the number of processors, but this is
not what you are looking for.
Getting the CPU unit count from WMI should however not take more than 50
msecs.
What OS and what WMI class are you using for this.
Willy.
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:uh******** ******@TK2MSFTN GP06.phx.gbl...
"not_a_comm ie" <no********@gma il.comwrote in message
news:11******** *************@d 30g2000prg.goog legroups.com...
>Is using System.Manageme nt in general a faux pas? It seems, after some web searching, that there is a fair amount of resistance to it because of speed and portability.
I need to know how many CPU sockets there are. I'm using System.Managem ent to do this. It takes about two seconds to do this. (Which, yes, is full-on crap for speed.) But what is the better way to determine the number of CPU sockets in Windows version >= 5 with a .NET >= 2.0 application?
Environment.Pro cessorCount, returns the number of processors, but this is
not what you are looking for.
Getting the CPU unit count from WMI should however not take more than 50
msecs.
What OS and what WMI class are you using for this.
Willy.
Following:
int processors;
SelectQuery query = new SelectQuery("se lect Deviceid from
Win32_Processor ");
using(Managemen tObjectSearcher searcher = new
ManagementObjec tSearcher(query ))
{
ManagementObjec tCollection processor= searcher.Get();
processors = processor.Count ;
}
takes 30...40msecs. when run on my box.
Note that the very first call can take some more time on some OS versions,
as the system has to start WMI (when not already).
started, anyway, this should be *much* less than 2 seconds, provided your
system is not running low on CPU or/and memory resources.
Willy.
I'm using WinXP SP2 on a core 2 duo. I'm thinking that my timer is
getting thrown off because this is being loaded in a static
constructor with other assemblies being loaded at the same time.
Here's the code:
if (Environment.OS Version.Version .Major >= 6 ||
Environment.OSV ersion.Platform == PlatformID.Unix )
return; // the bug we're working around exists in WinXP and older
ManagementClass mc = new ManagementClass ("Win32_Process or");
ManagementObjec tCollection mos = mc.GetInstances (); // get all the
processors from the device manager
List<stringcpuS ockets = new List<string>();
foreach (ManagementObje ct mo in mos)
{
string socketDesc =
mo.SystemProper ties["SocketDesignat ion"].Value.ToString ();
if(!cpuSockets. Contains(socket Desc))
cpuSockets.Add( socketDesc);
}
if (cpuSockets.Cou nt 1)
{
// my special handling here
}
So can I do something like this?
"select unique SocketDesignati on from Win32_Processor "
So I thought that
"select SocketDesignati on from Win32_Processor group by
SocketDesignati on"
would work (I would just use the count rows returned from that query).
Alas, it does not. Is SocketDesignati on not the same as
["SocketDesignat ion"].Value? Or does the "group by" in WQL just behave
in a fishy manner? This query throws an exception:
"select count(*) from Win32_Processor group by SocketDesignati on"
"not_a_comm ie" <no********@gma il.comwrote in message
news:11******** *************@x 35g2000prf.goog legroups.com...
So can I do something like this?
"select unique SocketDesignati on from Win32_Processor "
No, but if you are only interested in a single CPU's properties, you can do
the following to get at a specific instance.
string objPath = "Win32_Processo r.DeviceId='CPU 0'";
string socketType;
using(Managemen tObject service = new ManagementObjec t( new
ManagementPath( objPath)))
{
socketType = service.Propert ies["SocketDesignat ion"].Value.ToString ();
}
Willy.
"not_a_comm ie" <no********@gma il.comwrote in message
news:11******** **************@ i38g2000prf.goo glegroups.com.. .
So I thought that
"select SocketDesignati on from Win32_Processor group by
SocketDesignati on"
would work (I would just use the count rows returned from that query).
Alas, it does not. Is SocketDesignati on not the same as
["SocketDesignat ion"].Value? Or does the "group by" in WQL just behave
in a fishy manner? This query throws an exception:
"select count(*) from Win32_Processor group by SocketDesignati on"
While WQL looks like SQL it is not a full fledged SQL.
Willy.
No, but if you are only interested in a single CPU's properties, you can do
the following to get at a specific instance.
...
socketType = service.Propert ies["SocketDesignat ion"].Value.ToString ();
I'm interested in the count of unique SocketDesignati on values --
nothing else. It's creating instances of these objects that takes the
time, not the WQL. I was hoping to get all the information I needed
using WQL. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paul Gronka |
last post by:
I've got a VB.NET windows application (written in VS .NET 2003) that makes a
call to WMI for retrieving the MAC Address from the client's PC. It works on
4 out of the 5 PC's tested so far. All the workstations are DELLs running XP
SP1a with the 1.1 .NET Framework. The following line of code generates an
exception on the one PC:
Dim oMac As New
System.Management.ManagementClass("Win32_NetworkAdapterConfiguration")
The error it...
|
by: Brian Worth |
last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0
was able to shut down or restart the (windows XP) machine using a series of
API calls. (Getlasterror, GetCurrentProcess, OpenProcessToken,
LookupPrivilegeValue, AdjustTokenPrivilegese, ExitWindowsEx.
I am trying to avoid using any API calls if possible and to use managed code
instead. I couldn't find any easy way of doing this but searching the
Internet with...
|
by: james |
last post by:
I am attempting to write a VB.net program to alter remote registeries. I am
familiar with VBScript and so I was using WMI to connect to remote machines.
How would I do this in VB.Net?
I got this far..
======================================================
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btRDesktop.Click
Const HKEY_CURRENT_USER = &H80000001
|
by: lecnac |
last post by:
Sorry for the repost. I must have done something wrong when I tried to post
my reply (I can't seem to find it).
Anyway, I'd really appreciate any help that anyone could provide. My issue
is quickly becoming more and more urgent.
I've tried the code below using the server's local Administrator user name
and password. This gets me past the Access denied error but gives me a User
|
by: varois83 |
last post by:
Hi
I am currently learning the faux columns technique from various
tutorials but none of them tells me how to create a 774 px band in 3
colors in photoshop.
I understand I can create 3 individual GIF's for each column but the
tutorial I am really focusing on does one band only with the 3 colors.
I understand the technique but don't know how to create let's say a
774px wide band with Blue (200px) White(374px) and Red(200px).
This might...
| |
by: remya1000 |
last post by:
from my system i need to open a calculator in remote machine. and i'm using Vb.net and WMI. i need to pop up the calculator in remote machine, while i run one program in my system. while running in rmotre machine's taskmanager the calculator is displaying, but its not popuping.
i tried this code for pop up using Win32_ProcessStartup like this...
Module Module1
Sub Main()
Dim retValue As String
retValue = RunCommand("calc.exe",...
|
by: Marco Shaw |
last post by:
I've got some C# code to create a custom PowerShell cmdlet with these
statements:
....
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
....
My compile fails using csc.exe:
|
by: garks |
last post by:
I am using Exchange 2003(Exchange Hosting), C#.
I am trying to get Mailbox usage using WMI
But I follows the coding below, still cannot get the Mailbox usage.
Even though, I predefined the username and password.
Often gets "Access denied" while running the code.
I have tried to add the user to the \root\MicrosoftExchangeV2, and the
delegate control, but still cannot.
Is there anything I missing to add?
|
by: TamusJRoyce |
last post by:
Looking at various Holy Grail techniques for html layouts, I came across Faux Positioning Layout.
What I'm curious about is the differences between the two. I have no understanding of the Holy Grail, but have a working implementation of Faux Positioning (which may be a bit harder to do than the Holy Grail).
Both are compatible among various browsers, but are they really both the same thing? They both have negative margin-left css values,...
|
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...
|
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...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |