请大家帮我看看下面的代码
下面的代码是获取安装软件清单,运行是出现错误,请大家帮忙看看应该怎么写。
Imports System
Imports System.Management
Imports System.Windows.Forms
Namespace WMISample
Public Class CallWMIMethod
Public Overloads Shared Function Main() As Integer
Try
'下面一行运行出错:
Dim classInstance As New ManagementObject( _
"root\DEFAULT", _
"StdRegProv", Nothing)
' Obtain [in] parameters for the method
Dim inParams As ManagementBaseObject = _
classInstance.GetMethodParameters("GetStringValue")
' Add the input parameters.
inParams("hDefKey") = &H80000002
inParams("sSubKeyName") = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
inParams("sValueName") = "DisplayName"
' Execute the method and obtain the return values.
Dim outParams As ManagementBaseObject = _
classInstance.InvokeMethod("GetStringValue", inParams, Nothing)
' List outParams
Console.WriteLine("Out parameters:")
Console.WriteLine("ReturnValue: {0}", outParams("ReturnValue"))
Console.WriteLine("sValue: {0}", outParams("sValue"))
Catch err As ManagementException
MessageBox.Show("An error occurred while trying to execute the WMI method: " & err.Message)
End Try
End Function
End Class
End Namespace