Im confused... MSDN says the enumvalue method will return either a integer 0 or a non-zero error code. Why is it that when I run this code:
on a machine that doesnt exist that I get an invalidcast exception and "code" still equals to 0? here is all the code(this is not in use yet, I must messing around with it tryinng to understand it better):
Code is dim'ed public up further in the code.
VB.NET:
Dim code As Integer
oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!" & p_SystemPath & "\root\default:StdRegProv")
code = oReg.EnumValues(regHive, regPath, arrSubKeys)
on a machine that doesnt exist that I get an invalidcast exception and "code" still equals to 0? here is all the code(this is not in use yet, I must messing around with it tryinng to understand it better):
VB.NET:
Try
Dim strKeyPath As String
Dim arrSubKeys As Array
Dim subkey As String
Dim code As Integer
oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!" & p_SystemPath & "\root\default:StdRegProv")
code = oReg.EnumValues(regHive, regPath, arrSubKeys)
Console.WriteLine("Enum Suceeded: " & code)
Return arrSubKeys
oReg = Nothing
Catch invalidcast As System.InvalidCastException
Console.WriteLine("Enum Failed: " & code)
Console.WriteLine(invalidcast.StackTrace)
End Try
Code is dim'ed public up further in the code.