Sign in to follow this  
Followers 0
guysa

Help Converting WMI Script to Determine if a Computer is a Laptop or a Desktop Machine

4 posts in this topic

I'm trying to convert this WMI script to AU3

Thanks,

Guy Sasson

On Error Resume Next

Const wbemFlagReturnImmediately = &h10

Const wbemFlagForwardOnly = &h20

arrComputers = Array(".")

For Each strComputer In arrComputers

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure", "WQL", _

wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems

strChassisTypes = Join(objItem.ChassisTypes, ",")

Select Case strChassisTypes

Case 1

Wscript.Echo "Other"

Case 2

Wscript.Echo "Unknown"

Case 3

Wscript.Echo "Desktop"

Case 4

Wscript.Echo "Low Profile Desktop"

Case 5

Wscript.Echo "Pizza Box"

Case 6

Wscript.Echo "Mini Tower"

Case 7

Wscript.Echo "Tower"

Case 8

Wscript.Echo "Portable"

Case 9

Wscript.Echo "Laptop"

Case 10

Wscript.Echo "Notebook"

Case 11

Wscript.Echo "Handheld"

Case 12

Wscript.Echo "Docking Station"

Case 13

Wscript.Echo "All-in-One"

Case 14

Wscript.Echo "Sub-Notebook"

Case 15

Wscript.Echo "Space Saving"

Case 16

Wscript.Echo "Lunch Box"

Case 17

Wscript.Echo "Main System Chassis"

Case 18

Wscript.Echo "Expansion Chassis"

Case 19

Wscript.Echo "Sub-Chassis"

Case 20

Wscript.Echo "Bus Expansion Chassis"

Case 21

Wscript.Echo "Peripheral Chassis"

Case 22

Wscript.Echo "Storage Chassis"

Case 23

Wscript.Echo "Rack Mount Chassis"

Case 24

Wscript.Echo "Sealed-Case PC"

Case Else

Wscript.Echo "Unknown"

End Select

Next

Next

Share this post


Link to post
Share on other sites



Please have a look at ScriptOmatic in the Example Scripts forum. Select WMI Class "Win32_SystemEnclosure" and Scriptomatic will generate te AutoIt code for you.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi,

Welcome to the autoit forum :)

From a forum search :

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

guysa,

This was translated from the code you posted using Scriptomatic (as water advised)...

Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
$oWMISvc = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")

$colItems = $oWMISvc.ExecQuery("SELECT * FROM Win32_SystemEnclosure", "WQL", _
        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

For $objItem In $colItems
    Switch $objItem.ChassisTypes(0)
        Case 1
            ConsoleWrite('Other' & @LF)
        Case 2
            ConsoleWrite("Unknown" & @LF)
        Case 3
            ConsoleWrite("Desktop" & @LF)
        Case 4
            ConsoleWrite("Low Profile Desktop" & @LF)
        Case 5
            ConsoleWrite("Pizza Box" & @LF)
        Case 6
            ConsoleWrite("Mini Tower" & @LF)
        Case 7
            ConsoleWrite("Tower" & @LF)
        Case 8
            ConsoleWrite("Portable" & @LF)
        Case 9
            ConsoleWrite("Laptop" & @LF)
        Case 10
            ConsoleWrite("Notebook" & @LF)
        Case 11
            ConsoleWrite("Handheld" & @LF)
        Case 12
            ConsoleWrite("Docking Station" & @LF)
        Case 13
            ConsoleWrite("All-in-One" & @LF)
        Case 14
            ConsoleWrite("Sub-Notebook" & @LF)
        Case 15
            ConsoleWrite("Space Saving" & @LF)
        Case 16
            ConsoleWrite("Lunch Box" & @LF)
        Case 17
            ConsoleWrite("Main System Chassis" & @LF)
        Case 18
            ConsoleWrite("Expansion Chassis" & @LF)
        Case 19
            ConsoleWrite("Sub-Chassis" & @LF)
        Case 20
            ConsoleWrite("Bus Expansion Chassis" & @LF)
        Case 21
            ConsoleWrite("Peripheral Chassis" & @LF)
        Case 22
            ConsoleWrite("Storage Chassis" & @LF)
        Case 23
            ConsoleWrite("Rack Mount Chassis" & @LF)
        Case 24
            ConsoleWrite("Sealed-Case PC" & @LF)
        Case Else
            ConsoleWrite("Unknown" & @LF)
    EndSwitch
next

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  
Followers 0