I am using following vb6 code to check whether computer is desktop,laptop..etc But the code does not work properly and gives a run time error. I did the same code in VB.net and it works fine.When i did it in vb6 i am getting error.I know that i am missing something which is causing error.
I am getting error like " Run-time error 424 object required". when i checked error by break point i found that the error is for line "For Each strChassisType In objChassis.ChassisTypes" .(I think i have declared objChassis wrongly or chassisTypes requires declaration)
can anyone help me to solve the error?
The link i refered are http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx and http://blogs.technet.com/b/heyscript...p-machine.aspx
Below is the full code in vb6
I am getting error like " Run-time error 424 object required". when i checked error by break point i found that the error is for line "For Each strChassisType In objChassis.ChassisTypes" .(I think i have declared objChassis wrongly or chassisTypes requires declaration)
can anyone help me to solve the error?
The link i refered are http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx and http://blogs.technet.com/b/heyscript...p-machine.aspx
Below is the full code in vb6
Code:
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