System.Management.ManagementException:未找到

时间:2013-08-29 18:55:43

标签: vb.net

我在Windows XP上遇到有关我的应用程序的问题。我在Windows XP上收到以下错误,而在7/8它工作正常,我不知道下一步该怎么做。我调查了这个问题,发现它与WMI有关。我尝试在Windows XP系统上修复WMI,但它仍然无效。

这是我收到的错误:

  

**************例外文字**************

     

System.Management.ManagementException:找不到   System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus   System.Management.PropertyData.RefreshPropertyInfo()中的errorCode)   在System.Management.PropertyDataCollection.get_Item(String   propertyName)at   System.Management.ManagementBaseObject.GetPropertyValue(字符串   propertyName)at   System.Management.ManagementBaseObject.get_Item(String propertyName)
  at?。?(Object,EventArgs)at   System.Windows.Forms.Timer.OnTick(EventArgs e)at   System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)at at   System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,   IntPtr wparam,IntPtr lparam)

winmgmt服务正在所述系统上运行。有谁知道下一步该做什么?我目前正在安装Windows XP以便查明错误,但我可以使用本网站更有经验的成员提供的帮助。

这是模拟错误的代码。它在hdd.Get循环中停止

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox1.Text = TextBox1.Text + vbNewLine + "Starting process"
        Try
            Dim HDD_Serial As String = Nothing
            TextBox1.Text = TextBox1.Text + vbNewLine + "Step 1"
            Dim hdd As New ManagementObjectSearcher("select * from Win32_DiskDrive")
            TextBox1.Text = TextBox1.Text + vbNewLine + "Step 2"
            For Each hd In hdd.Get
                TextBox1.Text = TextBox1.Text + vbNewLine + "Step 2.x"
                HDD_Serial = hd("SerialNumber")
            Next
            TextBox1.Text = TextBox1.Text + vbNewLine + "Step 3"
            HDD_Serial = HDD_Serial.Replace(" ", "")
            TextBox1.Text = TextBox1.Text + vbNewLine + "Step 4"
            Dim regkey As String = "0000-0000-0000-0000"
            TextBox1.Text = TextBox1.Text + vbNewLine + "Step 5"
            Dim sstring As String = regkey + "|" + HDD_Serial
            TextBox1.Text = TextBox1.Text + vbNewLine + "Step 6"
            sstring = AESEncrypt(sstring, "4545664456", "1251545478")
            TextBox1.Text = TextBox1.Text + vbNewLine + "Step 7"
            sstring = StrToHex(sstring)
            TextBox1.Text = TextBox1.Text + vbNewLine + "Step 8"
            Dim rk2 As RegistryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\Test Key")
            TextBox1.Text = TextBox1.Text + vbNewLine + "Step 9"
            rk2.SetValue("regentry", sstring, RegistryValueKind.String)
            TextBox1.Text = TextBox1.Text + vbNewLine + "Step 10"
        Catch ex As Exception
            MessageBox.Show("Error")
            TextBox1.Text = TextBox1.Text + vbNewLine + vbNewLine + "-----------------------------------------------------" + vbNewLine + ex.ToString
        End Try
        TextBox1.Text = TextBox1.Text + vbNewLine + "End of log"
    End Sub

错误图片:

enter image description here

2 个答案:

答案 0 :(得分:1)

我设法为此找到了解决方法。我首先检测到Windows版本正在运行,然后在Windows XP的情况下,我使用API​​调用而不是WMI来获取HDD ID。如果版本高于XP,我使用WMI。我的应用程序使用的是.NET Framework 4.0,因此我不需要检查Windows的早期版本。

<DllImport("kernel32.dll")> _
    Private Shared Function GetVolumeInformation(ByVal PathName As String, ByVal VolumeNameBuffer As StringBuilder, ByVal VolumeNameSize As Int32, ByRef VolumeSerialNumber As Int32, ByRef MaximumComponentLength As Int32, ByRef FileSystemFlags As Int32, ByVal FileSystemNameBuffer As StringBuilder, ByVal FileSystemNameSize As Int32) As Long
    End Function

    Friend Function GetVolumeSerial(ByVal strDriveLetter As String) As String

        Dim serNum As System.Int32 = 0
        Dim maxCompLen As System.Int32 = 0
        Dim VolLabel As StringBuilder = New StringBuilder(256)
        Dim VolFlags As Int32 = New Int32
        Dim FSName As StringBuilder = New StringBuilder(256)
        strDriveLetter += ":\"
        Dim Ret As Long = GetVolumeInformation(strDriveLetter, VolLabel, CType(VolLabel.Capacity, Int32), serNum, maxCompLen, VolFlags, FSName, CType(FSName.Capacity, Int32))
        Return Convert.ToString(serNum)
    End Function

答案 1 :(得分:1)

如果您希望序列号的格式与从WMI“VolumeSerialNumber”获得的格式相同,请使用以下

Return Convert.ToString(serNum, 16).ToString.ToUpper 

这将为您提供十六进制字符串....