I have an app that uses WMI to pull values to generate a "unique" (I know there is a slight chance it's not really unique) identifying number for each computer that uses the app, for registration/licensing purposes. Some of my customers are now experiencing errors in this code and are being asked to go through registration again. I can't reproduce the error on my machine, so most of my conclusions are mostly guess work, but I think the issue is with this bit of code:
Private Function GetManagementObject(ByVal strProperty As String, ByVal strCollection As String) As String
Dim sb As New System.Text.StringBuilder
Try
Dim objSearcher As New ManagementObjectSearcher("SELECT " & strProperty & " FROM " & strCollection)
Dim objCollection As ManagementObjectCollection = objSearcher.Get
For Each objM As ManagementObject In objCollection
For Each objP As PropertyData In objM.Properties
If objP.Value IsNot DBNull.Value Then
sb.Append(objP.Value)
End If
Next
Next
objSearcher.Dispose()
objCollection.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return sb.ToString
End Function
I call this method with three different parm sets:
GetManagementObject("SerialNumber", "Win32_BaseBoard")
GetManagementObject("SerialNumber", "Win32_BIOS")
GetManagementObject("UUID", "Win32_ComputerSystemProduct")
I concat the return values together and then hash it to create my "unique" number. The issue now is that some users are getting this error:
Initialization failure
. They get it three times, so I'm confident that the cause is this method because it is called three times in the code that fires when they get the error. So does anyone know of any authorities and/or permissions issues that I need to check before using this code? Or a way around this error? Or even just why some people get it and others don't?
A lot of things I've found while searching for help involve trying to access the machine remotely. I'm not trying to connect remotely, the program just wants info from THIS computer. And I'm suspicious that there is another problem (or same problem but different symptom) because at another location in my app I have this bit of code:
sbException.Append("Operating System: " & My.Computer.Info.OSFullName.ToUpper & vbNewLine)
And I believe that this line is also causing an error. I can't say for certain it's that exact line, and I don't know the error message. This code is located in MyApplicationEvents UnhandledException where I have code to take care of unhandled exceptions, and I didn't put code in to give a detailed error message if THAT code encounters an exception, I just put a generic message box because I thought it would never happen (Learn from my mistakes, folks). Could there be some kind of permissions/authority issue that would cause BOTH of these issues? Any suggestions would be appreciated.