|
-
Mar 10th, 2006, 12:41 PM
#1
Thread Starter
Hyperactive Member
-
Mar 10th, 2006, 12:51 PM
#2
Frenzied Member
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.
-
Mar 10th, 2006, 01:01 PM
#3
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)
-
Mar 10th, 2006, 01:03 PM
#4
Frenzied Member
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?
-
Mar 10th, 2006, 01:05 PM
#5
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
Last edited by gigemboy; Mar 10th, 2006 at 01:09 PM.
-
Mar 10th, 2006, 01:10 PM
#6
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...
-
Mar 10th, 2006, 01:11 PM
#7
Thread Starter
Hyperactive Member
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 
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....?
-
Mar 10th, 2006, 01:14 PM
#8
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"
Last edited by gigemboy; Mar 10th, 2006 at 01:19 PM.
-
Mar 10th, 2006, 01:18 PM
#9
Thread Starter
Hyperactive Member
Re: Find most Hardware information?? (2005)
 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
-
Mar 10th, 2006, 01:20 PM
#10
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...
-
Mar 10th, 2006, 01:21 PM
#11
Thread Starter
Hyperactive Member
Re: Find most Hardware information?? (2005)
Yes you may also notice that that particular part is not being used at this time.
-
Mar 10th, 2006, 01:26 PM
#12
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...
-
Mar 10th, 2006, 01:36 PM
#13
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?? )
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
Last edited by gigemboy; Mar 10th, 2006 at 01:43 PM.
-
Mar 10th, 2006, 02:46 PM
#14
Thread Starter
Hyperactive Member
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...?
-
Mar 10th, 2006, 02:52 PM
#15
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...
-
Mar 10th, 2006, 05:10 PM
#16
Thread Starter
Hyperactive Member
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)
-
Mar 10th, 2006, 05:28 PM
#17
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...
-
Mar 11th, 2006, 12:17 PM
#18
Member
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|