我正在使用以下 vb6 代码来检查计算机是否是台式机、笔记本电脑等,但代码无法正常工作并出现运行时错误。我在 VB.net 中执行了相同的代码,它工作正常。当我在 vb6 中执行此操作时,我遇到了错误。我知道我遗漏了导致错误的东西。有人可以帮我解决错误吗?以下是vb6中的完整代码
Option Explicit
Private Sub Command1_Click()
Dim oWMI As Object
Dim oSystem As Object
Dim SQL As String
Dim objChassis As Object
Dim strChassisType As Object
Dim objWMIService As Object
Dim colChassis As Object
Dim strComputer As String
strComputer = "."
SQL = "Select * from Win32_SystemEnclosure"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colChassis = objWMIService.ExecQuery(SQL)
For Each objChassis In colChassis
For Each strChassisType In objChassis.ChassisTypes
Select Case strChassisType
Case 1
MsgBox ("Other")
Case 2
MsgBox ("Unknown")
Case 3
MsgBox ("Desktop")
Case 4
MsgBox ("Low Profile Desktop")
Case 5
MsgBox ("Pizza Box")
Case 6
MsgBox ("Mini Tower")
Case 7
MsgBox ("Tower")
Case 8
MsgBox ("Portable")
Case 9
MsgBox ("Laptop")
Case 10
MsgBox ("Notebook")
Case 11
MsgBox ("Handheld")
Case 12
MsgBox ("Docking Station")
Case 13
MsgBox ("All-in-One")
Case 14
MsgBox ("Sub-Notebook")
Case 15
MsgBox ("Space Saving")
Case 16
MsgBox ("Lunch Box")
Case 17
MsgBox ("Main System Chassis")
Case 18
MsgBox ("Expansion Chassis")
Case 19
MsgBox ("Sub-Chassis")
Case 20
MsgBox ("Bus Expansion Chassis")
Case 21
MsgBox ("Peripheral Chassis")
Case 22
MsgBox ("Storage Chassis")
Case 23
MsgBox ("Rack Mount Chassis")
Case 24
MsgBox ("Sealed-Case PC")
Case Else
MsgBox ("Unknown")
End Select
Next
Next
End Sub