Wmi搜索的帮助未发布计算机名称 [英] Help with Wmi search not releasing machine name

查看:54
本文介绍了Wmi搜索的帮助未发布计算机名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用WMI检查远程机器是否有特定信息的应用程序.我注意到,当我第一次搜索时,它会提取信息.而第二次搜索仍会提取第一笔机器信息.

我对搜索单击事件有一个清除命令,该命令会清除字段中的所有数据.但是它像我输入的第一个机器名称那样被困在内存中,而代码却无法看到它.

这是我的WMI代码.所有这些操作都只需单击一下按钮,即可在后台工作程序中运行.

I have the application that checks a remote machine for spcific information using WMI. i have noticed that when i search the first time it pulls the information. and the second time it searches it still pulls the first machien infomation.

I have a clear command on the search click event where it clears all the data from the fields. But it dosent help its like the first machine name i typed in is stuck in memory and the code itsnt seeing it.

here is my code for wmi. all of this is under a button click and runs in a background worker.

dim strComputer as string = machinenametextbox.text
Dim MyObjSearcher As System.Management.ManagementObjectSearcher
Dim MyColl As System.Management.ManagementObjectCollection
Dim MyObj As System.Management.ManagementObject
Dim MyConOptions As New System.Management.ConnectionOptions
With MyConOptions
    .Impersonation = System.Management.ImpersonationLevel.Impersonate
    .Authentication = System.Management.AuthenticationLevel.Packet
End With
Dim MyMgtScope As System.Management.ManagementScope
MyMgtScope = New System.Management.ManagementScope("\\" & strComputer & "\root\cimv2", MyConOptions)
MyMgtScope.Connect()
If MyMgtScope.IsConnected = False Then
    Exit Sub
End If
''----------------------------------------------------------------------------
''Basic machine INnformation for the left column
''----------------------------------------------------------------------------
Try
    MyObjSearcher = New System.Management.ManagementObjectSearcher(MyMgtScope.Path.ToString, _
            "Select * FROM Win32_OperatingSystem")
    MyColl = MyObjSearcher.Get
    For Each MyObj In MyColl
        OSNAME = (MyObj("caption").ToString())
        If OSNAME = "Microsoft Windows 7 Enterprise " Then
            OSNAME = "Windows 7"
            RadLabel1.Text = "CAE Info"
        ElseIf OSNAME = "Microsoft Windows XP Professional" Then
            OSNAME = "Windows XP"
            RadLabel1.Text = "Radia Info"
            CAE_Tab.Item.Visibility = ElementVisibility.Collapsed
        End If
        BackgroundWorkerMachineInfo.ReportProgress(10)
    Next

Catch ex As Exception
    OSNAME = "UnKnown"
End Try
Try
    MyObjSearcher = New System.Management.ManagementObjectSearcher(MyMgtScope.Path.ToString, _
            "Select * FROM Win32_OperatingSystem")
    MyColl = MyObjSearcher.Get
    For Each MyObj In MyColl
        SERVICEPACK = (MyObj("servicepackmajorversion").ToString())
        IMAGEDATE = ManagementDateTimeConverter.ToDateTime(CStr(MyObj("InstallDate")))
        LASTREBOOT = ManagementDateTimeConverter.ToDateTime(CStr(MyObj("LastBootUpTime")))
        BackgroundWorkerMachineInfo.ReportProgress(20)
    Next
Catch ex As Exception
    SERVICEPACK = "Unavailable"
    IMAGEDATE = "Unavailable"
    LASTREBOOT = "Unavailable"
End Try

推荐答案

不要清除它们.处置所有Scope和Searcher对象并创建新的对象.
Don''t clear them out. Dispose of all the Scope and Searcher objects and create new ones.


这篇关于Wmi搜索的帮助未发布计算机名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆