Connecting Tech Pros Worldwide Forums | Help | Site Map

System Information

BVS
Guest
 
Posts: n/a
#1: Apr 9 '07
I am moving from c++ to c# and I have been converting code to c#

I have not been able to convert the following code:

SYSTEM_INFO siSysInfo;
GetSystemInfo(&siSysInfo);
SystemID = siSysInfo.dwOemId.ToString();
ProcessorType = siSysInfo.dwProcessorType.ToString();
ProcessorMask = siSysInfo.dwActiveProcessorMask.ToString();

Can anyone offer suggestions?



Willy Denoyette [MVP]
Guest
 
Posts: n/a
#2: Apr 9 '07

re: System Information


"BVS" <nospam@tobvs.comwrote in message news:O%23mHcomeHHA.4772@TK2MSFTNGP05.phx.gbl...
Quote:
>I am moving from c++ to c# and I have been converting code to c#
>
I have not been able to convert the following code:
>
SYSTEM_INFO siSysInfo;
GetSystemInfo(&siSysInfo);
SystemID = siSysInfo.dwOemId.ToString();
ProcessorType = siSysInfo.dwProcessorType.ToString();
ProcessorMask = siSysInfo.dwActiveProcessorMask.ToString();
>
Can anyone offer suggestions?
>
>


The easiest way to get at this is by using System.Management and WMI's class
Win32_processor.

Following retrieves some properties of the first processor in the system.
....
string objPath = "Win32_Processor.DeviceId='CPU0'";
using(ManagementObject service = new ManagementObject( new ManagementPath(objPath)))
{
string manufacturer = (string)service.Properties["Manufacturer"].Value;
ushort family = (ushort)service.Properties["Family"].Value;
uint currentClockSpeed = (uint)service.Properties["currentClockSpeed"].Value;
Console.WriteLine("{0}, {1}, {2} MHz", manufacturer, family, currentClockSpeed);
}
....

Search MSDN for WMI's class "Win32_Processor" for details on the different properties and
their values.

Willy.

OD
Guest
 
Posts: n/a
#3: Apr 9 '07

re: System Information


There is also a simple trick only a few people seem to know : from the
Server Explorer in VS, just drag'n drop a WMI counter on your form.
This will add a component with the right WMI "Select" to get access to
this counter.

--


OD___
www.e-naxos.com


Willy Denoyette [MVP]
Guest
 
Posts: n/a
#4: Apr 9 '07

re: System Information


"OD" <webmaster @ e-naxos dot comwrote in message
news:mn.4b607d74f3b22ba3.18651@e-naxosdotcom...
Quote:
There is also a simple trick only a few people seem to know : from the Server Explorer in
VS, just drag'n drop a WMI counter on your form. This will add a component with the right
WMI "Select" to get access to this counter.
>
This is a VS RAD feature not available in all versions of VS, and it's a feature I don't
like, because:
1) it generates bloated code (like most wizards generated code).
2) it can only produce code for WMI classes available on your development system, what if
you need to target another OS system, or a system that runs specific WMI enabled services
(think SQL, Exchange ...)?

Willy.




BVS
Guest
 
Posts: n/a
#5: Apr 9 '07

re: System Information


Thank you!


OD
Guest
 
Posts: n/a
#6: Apr 9 '07

re: System Information


This is a VS RAD feature not available in all versions of VS, and it's a
Quote:
feature I don't like, because:
1) it generates bloated code (like most wizards generated code).
it's just a component with a SELECT from WMI. I'm not sure this is a
valid argument against this easy trick.
Quote:
2) it can only produce code for WMI classes available on your development
system, what if you need to target another OS system, or a system that runs
specific WMI enabled services (think SQL, Exchange ...)?
That's a point.
But why not use the simple way for all WMI counters you're sure to see
on all computers.
Simple tricks are allowing to spend more time on important code, this
is not "bad" to use simple tricks :-)

--


OD___
www.e-naxos.com


Willy Denoyette [MVP]
Guest
 
Posts: n/a
#7: Apr 9 '07

re: System Information


"OD" <webmaster @ e-naxos dot comwrote in message
news:mn.4c867d74804f923d.18651@e-naxosdotcom...
Quote:
Quote:
>This is a VS RAD feature not available in all versions of VS, and it's a feature I don't
>like, because:
>1) it generates bloated code (like most wizards generated code).
>
it's just a component with a SELECT from WMI. I'm not sure this is a valid argument
against this easy trick.
>
It's a component that includes and produces code, it's not a simple Select ..., however, you
aren't in control what code it produces,so you'll never know how this code works, you'll
never learn to do something more complex, you are at the mercy of a dumb and brain-dead
wizard.
Quote:
Quote:
>2) it can only produce code for WMI classes available on your development system, what if
>you need to target another OS system, or a system that runs specific WMI enabled services
>(think SQL, Exchange ...)?
>
That's a point.
But why not use the simple way for all WMI counters you're sure to see on all computers.
Because all system aren't the same, why restrict yourself to limiited/common set of
management objects? What if I need to manage IIS through WMI on the target system, when IIS
is not installed on the development system, what if I need to implement Exchange management
when Exchange is not available on the delelopment system? In that case your "simple trick"
won't work, you'll have to write code, you'll have to understand what *you* want the system
to do, not what the wizard allows you to do.

Also, WMI is not only about counters, it' s about a way to manage systems (hardware and
software) via a service with the help of several WMI providers and WMI enabled device driver
components.

Willy.


OD
Guest
 
Posts: n/a
#8: Apr 10 '07

re: System Information


It's a component that includes and produces code, it's not a simple Select
Quote:
..., however, you aren't in control what code it produces,so you'll never
know how this code works, you'll never learn to do something more complex,
you are at the mercy of a dumb and brain-dead wizard.
I respect your point of view but it is, for me, a little antiquated.
Cause if you don't use this component because you can't control all the
code within it, you'll have to avoid using almost all components...
And, of course, this not the direction of the history of IDE since now
more than 10 years. And VS 2005 and the next release are walking on
this same road.
About 'learning something more complex', writing code to achieve all
functions of a program is certainly a very good school, but it is not
the only one. And if we had to write code from scratch for each
program, I'm affraid applications will look today like the ones of the
70's.
Quote:
Because all system aren't the same, why restrict yourself to limiited/common
set of management objects?
because in the real life you never have to write a program for 'any
computer in the world that existed and will exist'. You write code for
a customer who expressed a specific need in a specific environment.
Of course, if you're coding for your pleasure, you can spend the rest
of your life writing a pac-man that will run on all known computers...
That can be a very interesting challenge and a good way to be famous...
Quote:
What if I need to manage IIS through WMI on the
target system, when IIS is not installed on the development system, what if I
need to implement Exchange management when Exchange is not available on the
delelopment system? In that case your "simple trick" won't work, you'll have
to write code, you'll have to understand what *you* want the system to do,
not what the wizard allows you to do.
In theory you're right.
But there is no "what if" in developer real life. As I said it, there
are customers wanting specific applications for specific environments.
If they want to change it in the future, things will be study at this
time. And generaly, technology has changed so much since the
application was written that it must be rewrite from scratch with a new
language, on a new platform, etc..
A "lifelong application" can't exist because technology is moving too
fast as the needs of customers.
Developers are not Pharons, they don't need to build pyramids which
will last for centuries... just because technology is not like the
rocks under the pyramids, technology is more like moving sand.
Quote:
Also, WMI is not only about counters, it' s about a way to manage systems
(hardware and software) via a service with the help of several WMI providers
and WMI enabled device driver components.
I did not said WMI is just about counters, read more carefully.
I just said that, for example, it is 'not bad' to use the trick I was
speaking about for simple things like counters. That makes a big
difference.

But one question : why are your splitting hairs ?

--


OD___
www.e-naxos.com


Willy Denoyette [MVP]
Guest
 
Posts: n/a
#9: Apr 10 '07

re: System Information


"OD" <webmaster @ e-naxos dot comwrote in message
news:mn.51047d743658469e.18651@e-naxosdotcom...
Quote:
Quote:
>It's a component that includes and produces code, it's not a simple Select ..., however,
>you aren't in control what code it produces,so you'll never know how this code works,
>you'll never learn to do something more complex, you are at the mercy of a dumb and
>brain-dead wizard.
>
I respect your point of view but it is, for me, a little antiquated. Cause if you don't
use this component because you can't control all the code within it, you'll have to avoid
using almost all components... And, of course, this not the direction of the history of
IDE since now more than 10 years. And VS 2005 and the next release are walking on this
same road.
As I said before, some wizards (like this one) are only available in the professional and
higher versions of VS, and why should I use VS to implement my projects?
In VS2005, there are wizards that are quite helpful in VS, while there are others that are
too basic, the one you are referring to is such one, once you know System.Management and WMI
you won't use it any longer even for the most simple things. The same is true for other
wizards like the "Windows Service Control", of little use for those who know what Services
are about, of little or no help for those who don't know what Services are about.
Quote:
About 'learning something more complex', writing code to achieve all functions of a
program is certainly a very good school, but it is not the only one. And if we had to
write code from scratch for each program, I'm afraid applications will look today like the
ones of the 70's.
>
I see you think RAD is the silver bullet, I know and other real developers know it's not.
Quote:
Quote:
>Because all system aren't the same, why restrict yourself to limited/common set of
>management objects?
>
because in the real life you never have to write a program for 'any computer in the world
that existed and will exist'. You write code for a customer who expressed a specific need
in a specific environment.
Right, and for instance that customer has expressed a need to manage IIS , do you have IIS
installed on your development machine, is it the same version as the one running on the
customers machine? A customer has expressed to manage his Vista Systems (added ~400 WMI
classes not available on XP), do you run Vista on your development system? If No, well, you
won't be able to access all the new classes using the wizard. Want some more samples?
Why you fail to accept that this *control* can only access YOUR own development system's
assets (HW and Software) but not those on any other system is beyond me.
You are never sure whether the WMI classes used exists on the other system or worse, you are
never sure they support the same properties (some are OS version and product version
dependent) and most importantly, you have no access at all to the classes that are part of
products that are missing on you system.

Quote:
Of course, if you're coding for your pleasure, you can spend the rest of your life writing
a pac-man that will run on all known computers... That can be a very interesting challenge
and a good way to be famous...
>
You don't get it do you, who's talking about "all known computers", I'm talking about
specific user requirements.
Quote:
Quote:
>What if I need to manage IIS through WMI on the target system, when IIS is not installed
>on the development system, what if I need to implement Exchange management when Exchange
>is not available on the delelopment system? In that case your "simple trick" won't work,
>you'll have to write code, you'll have to understand what *you* want the system to do,
>not what the wizard allows you to do.
>
In theory you're right.
I'm right in practice, if you don't read the WMI docs before starting to code, you won't
able to do anything else than the most simple things, you only will know what's available in
your restricted environment, and you will never learn what else is available.

Quote:
But there is no "what if" in developer real life. As I said it, there are customers
wanting specific applications for specific environments.
Right. That's exactly why I said you can't use the control to code against specific user
requirements.
Quote:
If they want to change it in the future, things will be study at this time. And generaly,
technology has changed so much since the application was written that it must be rewrite
from scratch with a new language, on a new platform, etc..
Who's talking about change?
Quote:
A "lifelong application" can't exist because technology is moving too fast as the needs of
customers.
Developers are not Pharons, they don't need to build pyramids which will last for
centuries... just because technology is not like the rocks under the pyramids, technology
is more like moving sand.
>
Quote:
>Also, WMI is not only about counters, it' s about a way to manage systems (hardware and
>software) via a service with the help of several WMI providers and WMI enabled device
>driver components.
>
I did not said WMI is just about counters, read more carefully.
I did, you where talking about counters...and the OP's question has nothing to do with
counters, it's about specific system info, like the processor's type and the OEM string.
These are exposed through the Win32_Processor class, but... some of it's properties are only
available on some OS versions. That means you have to read the doc's and code accordingly,
if you don't and use the RAD tool, you'll be missing the attributes unless you run the same
OS version as the target. Get it?

Quote:
I just said that, for example, it is 'not bad' to use the trick I was speaking about for
simple things like counters. That makes a big difference.
>
But one question : why are your splitting hairs ?
You are splitting hairs, I'm only trying to be correct.

Willy.



Closed Thread