Jump to content
Sign in to follow this  
idoru

Cannot retrive chassis type.

Recommended Posts

idoru

Hi Guys,

I have a script which I'm using to retrive the kind of chassis the machine its running on is.

Dim $strComputer, $strChassis
Dim $objWMIService, $objChassis, $colChassis, $objItem
$strComputer = "."
 $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")


 $colChassis = $objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure","",16)

For $objChassis in $colChassis
  For $objItem in $objChassis.ChassisTypes
    Select 
    Case $objItem=1 
        $strChassis = "Maybe Virtual Machine"
    Case $objItem=2 
        $strChassis = "??"
    Case $objItem=3 
        $strChassis = "Desktop"
    Case $objItem=4 
        $strChassis = "Thin Desktop"
    Case $objItem=5 
        $strChassis = "Pizza Box"
    Case $objItem=6 
        $strChassis = "Mini Tower"
    Case $objItem=7 
        $strChassis = "Full Tower"
    Case $objItem=8 
        $strChassis = "Portable"
    Case $objItem=9 
        $strChassis = "Laptop"
    Case $objItem=10 
        $strChassis = "Notebook"
    Case $objItem=11 
        $strChassis = "Hand Held"
    Case $objItem=12 
        $strChassis = "Docking Station"
    Case $objItem=13 
        $strChassis = "All in One"
    Case $objItem=14 
        $strChassis = "Sub Notebook"
    Case $objItem=15 
        $strChassis = "Space-Saving"
    Case $objItem=16 
        $strChassis = "Lunch Box"
    Case $objItem=17 
        $strChassis = "Main System Chassis"
    Case $objItem=18 
        $strChassis = "Lunch Box"
    Case $objItem=19 
        $strChassis = "SubChassis"
    Case $objItem=20 
        $strChassis = "Bus Expansion Chassis"
    Case $objItem=21 
        $strChassis = "Peripheral Chassis"
    Case $objItem=22 
        $strChassis = "Storage Chassis"
    Case $objItem=23 
        $strChassis = "Rack Mount Unit"
    Case $objItem=24 
        $strChassis = "Sealed-Case PC"
    EndSelect
  Next
Next
MsgBox(0, "Computer chassis type: " , $strChassis)

Unfortunatly this doesnt seem to work and errors out with the following

C:\Users\Idoru\Desktop\chassis.au3 (16) : ==> The requested action with this object has failed.:
$colChassis = $objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure","",16)
$colChassis = $objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure","",16)^ ERROR

Any ideas whats up?

Share this post


Link to post
Share on other sites
DjDeep00

@idoru...

Find out what the error is like this...

Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling.

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler

Dim $strComputer, $strChassis
Dim $objWMIService, $objChassis, $colChassis, $objItem
$strComputer = "."
$objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")


$colChassis = $objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure","",16)

For $objChassis in $colChassis
  For $objItem in $objChassis.ChassisTypes
    Select
    Case $objItem=1
        $strChassis = "Maybe Virtual Machine"
    Case $objItem=2
        $strChassis = "??"
    Case $objItem=3
        $strChassis = "Desktop"
    Case $objItem=4
        $strChassis = "Thin Desktop"
    Case $objItem=5
        $strChassis = "Pizza Box"
    Case $objItem=6
        $strChassis = "Mini Tower"
    Case $objItem=7
        $strChassis = "Full Tower"
    Case $objItem=8
        $strChassis = "Portable"
    Case $objItem=9
        $strChassis = "Laptop"
    Case $objItem=10
        $strChassis = "Notebook"
    Case $objItem=11
        $strChassis = "Hand Held"
    Case $objItem=12
        $strChassis = "Docking Station"
    Case $objItem=13
        $strChassis = "All in One"
    Case $objItem=14
        $strChassis = "Sub Notebook"
    Case $objItem=15
        $strChassis = "Space-Saving"
    Case $objItem=16
        $strChassis = "Lunch Box"
    Case $objItem=17
        $strChassis = "Main System Chassis"
    Case $objItem=18
        $strChassis = "Lunch Box"
    Case $objItem=19
        $strChassis = "SubChassis"
    Case $objItem=20
        $strChassis = "Bus Expansion Chassis"
    Case $objItem=21
        $strChassis = "Peripheral Chassis"
    Case $objItem=22
        $strChassis = "Storage Chassis"
    Case $objItem=23
        $strChassis = "Rack Mount Unit"
    Case $objItem=24
        $strChassis = "Sealed-Case PC"
    EndSelect
  Next
Next
MsgBox(0, "Computer chassis type: " , $strChassis)


Func MyErrFunc() 
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(4096 + 16, "ERROR", "A COM Error was intercepted!" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & $HexNumber & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )

   $g_eventerror = 1; something to check for when this function returns 
Endfunc

Share this post


Link to post
Share on other sites
rover

$colChassis = $objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure",'WQL',16)


I see fascists...

Share this post


Link to post
Share on other sites
November

Hi there,

Dim $strComputer, $strChassis
Dim $objWMIService, $objChassis, $colChassis, $objItem
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "."
$objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colChassis = $objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

For $objChassis in $colChassis
  For $objItem in $objChassis.ChassisTypes
    Select
    Case $objItem=1
        $strChassis = "Maybe Virtual Machine"
    Case $objItem=2
        $strChassis = "??"
    Case $objItem=3
        $strChassis = "Desktop"
    Case $objItem=4
        $strChassis = "Thin Desktop"
    Case $objItem=5
        $strChassis = "Pizza Box"
    Case $objItem=6
        $strChassis = "Mini Tower"
    Case $objItem=7
        $strChassis = "Full Tower"
    Case $objItem=8
        $strChassis = "Portable"
    Case $objItem=9
        $strChassis = "Laptop"
    Case $objItem=10
        $strChassis = "Notebook"
    Case $objItem=11
        $strChassis = "Hand Held"
    Case $objItem=12
        $strChassis = "Docking Station"
    Case $objItem=13
        $strChassis = "All in One"
    Case $objItem=14
        $strChassis = "Sub Notebook"
    Case $objItem=15
        $strChassis = "Space-Saving"
    Case $objItem=16
        $strChassis = "Lunch Box"
    Case $objItem=17
        $strChassis = "Main System Chassis"
    Case $objItem=18
        $strChassis = "Lunch Box"
    Case $objItem=19
        $strChassis = "SubChassis"
    Case $objItem=20
        $strChassis = "Bus Expansion Chassis"
    Case $objItem=21
        $strChassis = "Peripheral Chassis"
    Case $objItem=22
        $strChassis = "Storage Chassis"
    Case $objItem=23
        $strChassis = "Rack Mount Unit"
    Case $objItem=24
        $strChassis = "Sealed-Case PC"
    EndSelect
  Next
Next
MsgBox(0, "Computer chassis type: " , $strChassis)

Vista x32 tested!

Cheers

Edited by November

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites
idoru

Hi DJ

I get the error as shown in these screen shots. post-42841-1245330765_thumb.jpg and post-42841-1245330835_thumb.gif

I should mention that I have a vbs version of this that works fine

Share this post


Link to post
Share on other sites
idoru

Thanks to Rover for his fix!!

Also thanks to November and DJ! :D

Share this post


Link to post
Share on other sites
Inverted

Haha, weird, didn't know about this. I guess the motherboard reports its factory-default chassis.

Edited by Inverted

Share this post


Link to post
Share on other sites
November

(almost) All hardware info is "licked" by windows.

Then only do a simple WSQL query.

Watch out with different windows versions... not all classes are available.

look up for scriptomatic in forum.

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.