gpt4 book ai didi

vb.net - 系统管理.管理异常: Not found

转载 作者:行者123 更新时间:2023-12-02 04:54:49 26 4
gpt4 key购买 nike

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

这是我收到的错误:

************** Exception Text **************

System.Management.ManagementException: Not found at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.PropertyData.RefreshPropertyInfo() at System.Management.PropertyDataCollection.get_Item(String propertyName) at System.Management.ManagementBaseObject.GetPropertyValue(String 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 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

最佳答案

我设法找到了解决此问题的方法。我首先检测正在运行的 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

关于vb.net - 系统管理.管理异常: Not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18518955/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com