请大家帮我看看下面的代码

lauted 2008-08-05 03:38:00
下面的代码是获取安装软件清单,运行是出现错误,请大家帮忙看看应该怎么写。


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
...全文
98 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lauted 2008-08-06
  • 打赏
  • 举报
回复
顶一下。
破咖啡罐子 2008-08-05
  • 打赏
  • 举报
回复
Imports System.Management
Management 我怎么没有呢?
lauted 2008-08-05
  • 打赏
  • 举报
回复
没有人能帮我看一下吗?谢谢大家了。

16,549

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧