Find most Hardware information?? (2005)
Basically, I Would like to put the following information into a textbox, some of which I already have (Marked with :thumb:):
Processor Information - Mostly :thumb:
List of all Drives (Sizes, Letters and Location [Primary Disk, Secondary Disk etc.]) - -
Display Type (VGA?) - -
RAM Size - -
Many thanks in advance.
Regards,
Rudi
Re: Find most Hardware information?? (2005)
Take a look at the WMI classes.
Specificly Computer System Hardware and Operating System.
Search for WMI in the .Net code bank. Gigemboy has a good example on how to use WMI.
Re: Find most Hardware information?? (2005)
Check the codebank submission in my signature. There is a WMI example in there, as well as a class library in the same thread that I created that has the Win32 WMI classes inside of it (200+ classes) that can pull all sorts of hardware information, as well as expose the properties of each WMI class inside of the IDE in intellisense so you can see which ones you can use without having to resort to the MSDN documentation.... and also returns enumerated values of the properties if found (instead of just meaningless numbers that you would have to look up in order to know what they mean) :)
Re: Find most Hardware information?? (2005)
Gig, your class in the code bank, that wouldn't happen to have the ability to change display settings? Would it?
Re: Find most Hardware information?? (2005)
No, It doesnt give you the ability to change anything. The classes used are all classes that just return information. They arent the WMI classes or functions that you can use in order to change system information, just the ones to retrieve it... Havent messed with changing info with WMI yet, maybe sometime in the future :p
Re: Find most Hardware information?? (2005)
On another note, if you want a quick example of the type of information you can pull with each WMI class, you can try out MySystemSpy in my sig. Its a program I made that uses a lot of the classes in the class library. You can see all of the different properties you can pull... The WMI class that each one uses is just the name you click on with "Win32_" appended onto the front of it...
Re: Find most Hardware information?? (2005)
Hmm I have used it for processor information perfectly fine, and I had the same error that I have now, only thing is, I don't know how I fixed it :eek:
Here is my code and the error:
VB Code:
Dim query1 As New Management.SelectQuery("Win32_PhysicalMedia")
Dim search1 As New Management.ManagementObjectSearcher(query1)
Dim info1 As New Management.ManagementObject
For Each info1 In search1.Get()
RichTextBox1.Text = RichTextBox1.Text & vbNewLine & "Disks: " & info1("caption").ToString() ' & " - " & info("Status").ToString()
Next
Error: System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
I wonder what is the problem....?
Re: Find most Hardware information?? (2005)
Those properties (caption and status) dont exist with the Win32_PhysicalMedia class. Refer to the documentation on the class in order to see what properties you can pull, or reference the class library I made so it exposes all of the properties you can pull in the IDE, or Try out MySystemSpy so you can get a list of all the properties :)
That is also just the physical disk drive, if you want the individual disk drive letters, you would need to use Win32_LogicalDisk
***EDIT - I also see that you are using "info" at the end of your code instead of "info1" ;)
Re: Find most Hardware information?? (2005)
Quote:
Originally Posted by gigemboy
Those properties (caption and status) dont exist with the Win32_PhysicalMedia class.
http://msdn.microsoft.com/library/de...sicalmedia.asp
They do :(
Re: Find most Hardware information?? (2005)
I edited my post above, but I had noticed you were using "info" instead of "info1" at the end of your code...
Re: Find most Hardware information?? (2005)
Yes you may also notice that that particular part is not being used at this time. :(
Re: Find most Hardware information?? (2005)
I just tested it out, and it is the Caption and Status property that is the problem... i dont think they actually exist, even though the documentation says so. It is not listed when you view the properties using the following:
VB Code:
For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()
'displays all properties for object in Mof format (there are other formats)
MessageBox.Show(Mgmt.GetText(Management.TextFormat.Mof))
Next
Nor is it listed in the class library that I created, which was class files that were generated from a tool from Microsoft...
Re: Find most Hardware information?? (2005)
Ahhhhh!! I remember now. The property is null... it exists but the value is null. I checked the class library and it is in fact in there. You get the error because you are trying to convert a null value to a string (I think?? :confused: )
The class library takes nulls into account as well, and won't generate an exception when a property is null... it would just return an empty string...
ANd a short example if you just reference the class library...
VB Code:
Dim PM As New Win32.PhysicalMedia
For Each Media As Win32.PhysicalMedia In PM.GetInstances
MessageBox.Show(Media.Caption) 'shows empty string
Next
Re: Find most Hardware information?? (2005)
Well I only get Tag and Serial number when I use the code previous to the last post...
Maybe Windows Vista is blocking some information...?
Re: Find most Hardware information?? (2005)
It is because the rest are null values. When calling GetText, it isnt going to return any of the properties that have null values...
Re: Find most Hardware information?? (2005)
Exactly, but I'm sure that it will have more information than just the tag and serial number, or am I wrong, Windows Explorer etc. can find out information like the name, maybe Vista is blocking access to some services as surely the name should be shown! (I know that Vista has blocked many things I have tried to do in the past)
Re: Find most Hardware information?? (2005)
PhysicalMedia is different... I think you are thinking something like the Win32_DiskDrive WMI class . This returns more relevant values for the hard disk, like partitions, size, sectors, heads, etc. Also, the Win32_LogicalDisk WMI class returns information for the actual drive letters, like c:\, d:\, including network drives...
Re: Find most Hardware information?? (2005)
Hi!!
it seems I'm missing something, i can't instance Win32 or WMI class, Visual Studio 2005 Express, tells me that Win32.PhysicalMedia is not defined.... ?
I'm interested in hardware info too, because i want somehow to protect my application from unauthorized redistribution...