|
-
Jul 12th, 2006, 02:26 PM
#1
Thread Starter
Junior Member
[RESOLVED] [2005] unhandled exception system.management...HELP!
i am by no means an expert at this type of code, I am simply trying to put together an app to collect some system information. It has been running well on about 100 out of 130 systems, the other 30 it throws an unhandled exception.
ERROR:
Unhandled Exception: System.Management.ManagementException: Not Found
at System.Management.ManagementScope.Initialize ()
at System.Management.ManagementObjectSearcher.Initialize ()
at System.Management.ManagementObjectSearcher.Get ()
at Inventory.Module1.Main()
CODE (what looks relivent):
Sub Main()
Dim objCS As ManagementObjectSearcher
objCS = New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")
Dim objOS As ManagementObjectSearcher
objOS = New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
Dim objProc As ManagementObjectSearcher
objProc = New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
Dim oQuery As New System.Management.ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3")
Dim oSearcher As New ManagementObjectSearcher(oQuery)
Dim oReturnCollection As ManagementObjectCollection = oSearcher.Get()
Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
'get OS
For Each objMgmt In objOS.Get
OSInfo = objMgmt("name").ToString()
Next
'get model, manufacterer and memory
For Each objMgmt In objCS.Get
Manu = objMgmt("manufacturer").ToString()
Model = objMgmt("model").ToString()
TPM = objMgmt("totalphysicalmemory").ToString()
Next
'get processor name and clock speed
For Each objMgmt In objProc.Get
PClock = objMgmt("maxclockspeed").ToString()
PName = objMgmt("name").ToString()
Next
'get disk space and freespace
For Each oReturn As ManagementObject In oReturnCollection
DSize = oReturn("FreeSpace").ToString()
DSpace = oReturn("Size").ToString()
Next
Anyone have any clue why it might do this on some systems and not others?
-
Jul 12th, 2006, 10:14 PM
#2
Re: [2005] unhandled exception system.management...HELP!
It is dependent on the WMI (Windows Management Instrumentation) service. The WMI service needs to be running in order for it to work, which means you should first be checking the service to see if it is started, and if it isnt, attempt to start it, and bringing up a message if the startup failed, or something to that effect. You can control services with the ServiceController class, and an example of using it can be found below:
http://www.vbforums.com/showthread.php?t=392369
You can also check out my codebank submission in my signature over WMI for an example, as well as a class library of hundreds of WMI hardware classes, with properties all exposed to you in the ide...
-
Jul 14th, 2006, 10:36 AM
#3
Thread Starter
Junior Member
Re: [2005] unhandled exception system.management...HELP!
Check several systems and restarted the WMI service, still the same issue. I tried both with code and manually with services.msc. Any other ideas about what Might be going wrong? If needed I can send you the full code.
-
Jul 24th, 2006, 12:50 PM
#4
Thread Starter
Junior Member
Re: [2005] unhandled exception system.management...HELP!
Ok found that reinstalling .NET 2.0 fixed some of the systems others still throw an unhandled exception. here is one function's exact code that is throwing the error...
VB Code:
Private Function GetSTag() As String
'WMI delare
Dim dellTag As String = ""
Dim query As New SelectQuery("Win32_BIOS")
Dim searcher As New ManagementObjectSearcher(query)
Dim results As ManagementObjectCollection = searcher.Get
Dim enumerator As ManagementObjectCollection.ManagementObjectEnumerator = results.GetEnumerator
enumerator.MoveNext()
Dim properties As ManagementObject = enumerator.Current
'pass var delare/set
dellTag = properties("SerialNumber").ToString
searcher.Dispose()
results.Dispose()
enumerator.Dispose()
properties.Dispose()
dellTag = Replace(dellTag, " ", "")
'return var
Return dellTag
End Function
-
Jul 24th, 2006, 02:00 PM
#5
Re: [2005] unhandled exception system.management...HELP!
Well put that code in between try catch blocks to catch the error... and the line it is ocurring on....
-
Jul 24th, 2006, 02:07 PM
#6
Thread Starter
Junior Member
Re: [2005] unhandled exception system.management...HELP!
even in a try...catch statement if the program continues I have about 7 other WMI functions that will also throw that error. if I put each of them in catch I pretty much defeated the reason for the program =(. I am not able to install VB on the stations that are having issues or I would walk through with debugger. I pretty much need to get to the root o that WMI error....unless someone has another idea of how to get it to work...
-
Jul 24th, 2006, 02:24 PM
#7
Re: [2005] unhandled exception system.management...HELP!
And are you sure the WMI service is running on the machines that still have the problem? What is the exception? Is it different than in the original post? Putting Try Catch blocks around it, handling the exceptions, and displaying the exception information would tell you this without having to have the visual studio IDE on the other machines, since it would be coded into the program.
-
Jul 24th, 2006, 02:27 PM
#8
Thread Starter
Junior Member
Re: [2005] unhandled exception system.management...HELP!
WMI is indeed running, I have stopped and restarted it manually in services.msc. The exception is simply "unhandled exception", how would I output some more error info using catch (bit new to debugging on this level) Could you perhaps modify the function above to output something useful...then I can run it.
-
Jul 24th, 2006, 02:51 PM
#9
Re: [2005] unhandled exception system.management...HELP!
An example of catching an exception, and showing various parts of it. Notice the stack trace message, the line number that the error ocurred on is at the end of it...
VB Code:
Try
'a file the doesnt exist will throw an error
Dim MyReader As New System.IO.StreamReader("c:\ThisIsNotAFile.txt")
Catch ex As Exception
'error message
MessageBox.Show("Message:" & ex.Message)
MessageBox.Show("Source:" & ex.Source)
'stack trace, which displays the line number of the error
MessageBox.Show("StackTrace:" & ex.StackTrace)
End Try
I would suggest Googling for some Visual Studio Debugging tutorials, as knowledge of debugging is essential information, and will cause much less headaches
Last edited by gigemboy; Jul 24th, 2006 at 02:54 PM.
-
Jul 24th, 2006, 03:07 PM
#10
Thread Starter
Junior Member
Re: [2005] unhandled exception system.management...HELP!
Ok tried that, it gives me a set of error messages that say the same thing as the initial error message I posted still gives:
Unhandled Exception: System.Management.ManagementException: Not Found
at System.Management.ManagementScope.Initialize ()
at System.Management.ManagementObjectSearcher.Initialize ()
at System.Management.ManagementObjectSearcher.Get ()
at Inventory.Module1.Main()
-
Jul 24th, 2006, 03:40 PM
#11
Re: [2005] unhandled exception system.management...HELP!
but where? What line? It could be that the particular machine does not have a property for "SerialNumber" or something to that matter, or the property might be null or something on those particular systems. I am not sure because I still don't know what line the error is ocurring on... You might want to try my WMI codebank submission and utilize the DLL class library I created for it instead. It should handle null values and what not...
If you want to check, you can download MySystemSpy under my freeware programs and run it on those questionable systems. Check out the BIOS section (which uses Win32_Bios.. under motherboard/controller/ports) and see what you pull up for the serial number, or if there are some sort of problems with it. The prog uses WMI for all of the information, and utilizes the DLL that I created and linked in my WMI codebank submission...
Last edited by gigemboy; Jul 24th, 2006 at 03:49 PM.
-
Jul 24th, 2006, 03:57 PM
#12
Thread Starter
Junior Member
Re: [2005] unhandled exception system.management...HELP!
It seems the systems WMI is just completely screwed....goning to try a reinstall
-
Jul 24th, 2006, 04:06 PM
#13
Re: [2005] unhandled exception system.management...HELP!
Are you sure? It could just be a null value for the field, which would pull an error...it would make sense... If you run MySystemSpy on one of the problem systems and it works fine and pulls info, then WMI is fine....
-
Jul 24th, 2006, 04:08 PM
#14
Thread Starter
Junior Member
Re: [2005] unhandled exception system.management...HELP!
The system is identical to 4 others that are working correctly, they were all imaged at the same time ahve the same patches etc. I am going to ghost one of the others over to it...should fix the issue.
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
|