|
Do we need to change the scope from machine to machine?
When i tried your code am getting Error Msg as "Object reference not set to an instance of an object."
|
|
|
|
|
Thoombath wrote: Do we need to change the scope from machine to machine?
Yes. If you want to connect to a different machine you have to change the \\.\root\cimv2 to \\machineName\root\cimv2 .
Thoombath wrote: When i tried your code am getting Error Msg as "Object reference not set to an instance of an object."
It would help to know on which line this is occuring.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I changed to my Computer Name still that Error is coming.
Its occuring on :
Dim newItem As New ListViewItem(New String() {CStr(obj("Tag")), CStr(obj("SerialNumber")).Trim})
|
|
|
|
|
Then no SerialNumber object was returned, or that object isn't in the collection. Calling Trim on it fails because you can't do this:
Nothing.Trim
Wrap that line and the next one in a Try/Catch block to ignore any errors:
For Each obj As ManagementObject In objectCollection
' The ListView is assumed to have two columns setup to old these.
Try
Dim newItem As New ListViewItem(New String() {CStr(obj("Tag")), CStr(obj("SerialNumber")).Trim})
ListView1.Items.Add(newItem)
Catch
' Warning! This will ignore ANY AND ALL ERRORS with the above two lines of code!
' In a production environment, this is usually NOT a good idea!
End Try
Next
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Now the Error is gone. But nothing is populated on the List View.
This might be coz of my hard drives. Is this requires Administrative login or role to function this Method?
Thanks
|
|
|
|
|
The code has to have FullTrust in order to run. That means, by default, it needs to be run from the local workstation, or if querying other machines, needs to have admin rights to the target workstation.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I am trying this in an Windows Based Application and am quering to the local machine. Am a user under a Domine. Will this be the reason for not getting the answer?
|
|
|
|
|
So long as that account has admin rights to the machine, it should work. The other possibility is that the data isn't being created by any providers installed on the machine. People keep asking "How do I get the serial number of my motherboard using WMI??". Well, if the manufacturer of the motherboard doesn't provide a WMI provider, you can't. On top of that, there's nothing that says the manufacturer, even though they are providing a WMI Provider, has to fill in these kinds of details.
Like I said in my previous post, I ran the code on one of my test machines (with 6 hard drives in it) and only 2 returned serial numbers!
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Anyways thanks Dave.
I will try it with other systems and see how it goes.
Regards,
Anas TM
|
|
|
|
|
I am looking for retrieving the Serial Number and Hard Disc detail of an Windows Xp Machine using Vb.Net. I found some code using query to Win32_PhysicalMedia, but its not working properly. Can any one help me in this...
Regards
Anas
|
|
|
|
|
Let's see the code you're using. WMI is about the only method you've got to get this information. But, there's nothing that says the hardware or the provider for it has to fill in all the details of what you're looking for, like the serial number.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi Dave,
I have posted the code for getting Serial Number using the WMI
The post subject is SerialNumber of an Xp Machine.
Thanks,
Anas
|
|
|
|
|
Sorry if this is a silly question and I may just be being thick, but I can't seem to get a startup project going as I don't want to use a one-click setup, in the MS instructions it says, you go file ==> add ==> New Project, and select startup project from there, I just don't have this option at all, I'm using VB.net 2005 express edition.
many thanks..
|
|
|
|
|
I think you're referring to the Setup project, not Startup.
And no, the Express Editions don't come with one. They're relegated to ClickOnce deployment.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
yup, setup project and b****r I had an idea that might be the case...
|
|
|
|
|
|
The Express Editions don't come with the Setup projects you use in your article. Express only uses ClickOnce Deployment.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I guess it shows that I don't use Express Edition of VS.
Thanks,
Ben
|
|
|
|
|
Neither do I...
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
But you know more about its limitations then I do.
Ben
|
|
|
|
|
The results of a quick visit to the Visual Studio Developer Center on MSDN. Look for the Product edition comparison in the navigation tree on the left.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
You know it is sort of funny they don't include it. It is not like you don't need to deploy your apps. I guess they just want everyone to start using clickonce.
Ben
|
|
|
|
|
kubben wrote: You know it is sort of funny they don't include it. It is not like you don't need to deploy your apps.
The Express Editions weren't meant to build production apps. They're meant to plaay around with so you can get an introduction to the languages they support and the .NET Framework. Those Editions don't even have project templates for Windows Services, Web Services, ..., just Windows Forms.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Just because they weren't ment to build production apps, doesn't mean it isn't happening. My article is on the windows setup project. I never did one on the web setup. So from my perspective it still make sense since all you have is a windows project. You probably want a way to deploy it. I can understand the windows services not being there. Anyway, I guess it doesn't have to make sense. I am sure somewhere somebody said, "hey look if we leave the windows setup project out of the express version it will save us like half a cent somehow and that adds up you know?" I am sure that nobody is going to buy the full version of VS just so they can get windows setup projects.
Ben
|
|
|
|
|
on that note if I write my own setup project template anyone any objections if I post it up on here...
|
|
|
|