Thursday, 14 February 2013

Getting Motherboard Information using JavaScript



Win32_BaseBoard: The Win32_BaseBoard WMI class represents a baseboard, which is also known as a motherboard or system board.
Win32_MotherboardDevice: The Win32_MotherboardDevice WMI class represents a device that contains the central components of the Windows computer system.
Name
WMI Class
Data type
Description
Availability
Win32_MotherboardDevice
Uint16
Availability and status of the device
HostingBoard
Win32_BaseBoard
Boolean
If TRUE, the card is a motherboard or a baseboard in a chasis
InstallDate
Win32_BaseBoard
Datetime
Date and time the object was installed
Manufacturer
Win32_BaseBoard
String
Name of the organization responsible for producing the physical element
Model
Win32_BaseBoard
String
Name by which the physical element is known
PartNumber
Win32_BaseBoard
String
Part number assigned by the organization responsible for producing or manufacturing the physical element
PNPDeviceID
Win32_MotherboardDevice
String
Windows Plug and Play device identifier of the logical device
PrimaryBusType
Win32_MotherboardDevice
String
Primary bus type of the motherboard
Product
Win32_BaseBoard
String
Baseboard part number defined by the manufacturer
Removable
Win32_BaseBoard
Boolean
If TRUE, a package is removable
Replaceable
Win32_BaseBoard
Boolean
If TRUE, a package is replaceable
RevisionNumber
Win32_MotherboardDevice
String
Revision number of the motherboard
SecondaryBusType
Win32_MotherboardDevice
String
Secondary bus type of the motherboard
SerialNumber
Win32_BaseBoard
String
Manufacturer-allocated number used to identify the physical element
Status
Win32_BaseBoard
String
Current status of the object
SystemName
Win32_MotherboardDevice
String
Name of the scoping system
Version
Win32_BaseBoard
String
Version of the physical element

Availability Properties:
Value
Meaning
1
Other
2
Unknown
3
Running or Full Power
4
Warning
5
In Test
6
Not Applicable
7
Power Off
8
Off Line
9
Off Duty
10
Degraded
11
Not Installed
12
Install Error
13
Power Save – Unknown
14
Power Save – Low Power Mode
15
Power Save – Standby
16
Power Cycle
17
Power Save – Warning

Status Properties:
·         OK
·         Error
·         Degraded
·         Unknown
·         Starting
·         Pred Fail
·         Stopping
·         Service
·         Stressed
·         NonRecover
·         No Contact
·         Lost Comm
Write the following code:
Script.js
var strComputer = ".";
var SWBemlocator = new ActiveXObject("WbemScripting.SWbemLocator");
var objWMIService = SWBemlocator.ConnectServer(strComputer, "/root/CIMV2");
var baseColItems = objWMIService.ExecQuery("SELECT * FROM Win32_BaseBoard");
var motherColItems = objWMIService.ExecQuery("SELECT * FROM Win32_MotherboardDevice");
var baseE = new Enumerator(baseColItems);
var motherE = new Enumerator(motherColItems);

function Availability() {
    for (; !motherE.atEnd(); motherE.MoveNext()) {
        return GetAvailability(motherE.item().Availability);
    }
}

function HostingBoard() {
    for (; !baseE.atEnd(); baseE.MoveNext()) {
        return baseE.item().HostingBoard;
    }
}

function InstallDate() {
    for (; !baseE.atEnd(); baseE.MoveNext()) {
        return ConvertToDateTime(baseE.item().InstallDate);
    }
}

function Manufacturer() {
    for (; !baseE.atEnd(); baseE.MoveNext()) {
        return baseE.item().Manufacturer;
    }
}

function Model() {
    for (; !baseE.atEnd(); baseE.MoveNext()) {
        return baseE.item().Model;
    }
}

function PartNumber() {
    for (; !baseE.atEnd(); baseE.MoveNext()) {
        return baseE.item().PartNumber;
    }
}

function PNPDeviceID() {
    for (; !motherE.atEnd(); motherE.MoveNext()) {
        return motherE.item().PNPDeviceID;
    }
}

function PrimaryBusType() {
    for (; !motherE.atEnd(); motherE.MoveNext()) {
        return motherE.item().PrimaryBusType;
    }
}

function Product() {
    for (; !baseE.atEnd(); baseE.MoveNext()) {
        return baseE.item().Product;
    }
}

function Removable() {
    for (; !baseE.atEnd(); baseE.MoveNext()) {
        return baseE.item().Removable;
    }
}

function Replaceable() {
    for (; !baseE.atEnd(); baseE.MoveNext()) {
        return baseE.item().Replaceable;
    }
}

function RevisionNumber() {
    for (; !motherE.atEnd(); motherE.MoveNext()) {
        return motherE.item().RevisionNumber;
    }
}

function SecondaryBusType() {
    for (; !motherE.atEnd(); motherE.MoveNext()) {
        return motherE.item().SecondaryBusType;
    }
}

function SerialNumber() {
    for (; !baseE.atEnd(); baseE.MoveNext()) {
        return baseE.item().SerialNumber;
    }
}

function Status() {
    for (; !baseE.atEnd(); baseE.MoveNext()) {
        return baseE.item().Status;
    }
}

function SystemName() {
    for (; !motherE.atEnd(); motherE.MoveNext()) {
        return motherE.item().SystemName;
    }
}

function Version() {
    for (; !baseE.atEnd(); baseE.MoveNext()) {
        return baseE.item().Version;
    }
}

function GetAvailability(availability) {
    switch (availability) {
        case 1: return "Other";
        case 2: return "Unknown";
        case 3: return "Running or Full Power";
        case 4: return "Warning";
        case 5: return "In Test";
        case 6: return "Not Applicable";
        case 7: return "Power Off";
        case 8: return "Off Line";
        case 9: return "Off Duty";
        case 10: return "Degraded";
        case 11: return "Not Installed";
        case 12: return "Install Error";
        case 13: return "Power Save - Unknown";
        case 14: return "Power Save - Low Power Mode";
        case 15: return "Power Save - Standby";
        case 16: return "Power Cycle";
        case 17: return "Power Save - Warning";
        default: return "Unknown";
    }
}

function ConvertToDateTime(unconverted) {
    var converted = "";
    if (unconverted != null) {
        var year = parseInt(unconverted.substr(0, 4));
        var month = parseInt(unconverted.substr(4, 2));
        var date = parseInt(unconverted.substr(6, 2));
        var hours = parseInt(unconverted.substr(8, 2));
        var minutes = parseInt(unconverted.substr(10, 2));
        var seconds = parseInt(unconverted.substr(12, 2));
        var meridian = "AM";
        if (hours > 12) {
            hours -= 12;
            meridian = "PM";
        }
        converted = date.toString() + "/" + month.toString() + "/" + year.toString() + " " + hours.toString() + ":" + minutes.toString() + ":" + seconds.toString() + " " + meridian;
    }
    return converted;
}

Index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Motherboard</title>
        <style type="text/css">
            th
            {
                text-align: left;
            }
        </style>
        <script type="text/javascript" src="Script.js"></script>
        <script type="text/javascript">
            function load() {
                show("availability", Availability());
                show("hostingBoard", HostingBoard());
                show("installDate", InstallDate());
                show("manufacturer", Manufacturer());
                show("model", Model());
                show("partNumber", PartNumber());
                show("pnpDeviceID", PNPDeviceID());
                show("primaryBusType", PrimaryBusType());
                show("product", Product());
                show("removable", Removable());
                show("replaceable", Replaceable());
                show("revisionNumber", RevisionNumber());
                show("secondaryBusType", SecondaryBusType());
                show("serialNumber", SerialNumber());
                show("status", Status());
                show("systemName", SystemName());
                show("version", Version());
            }

            function show(id, value) {
                document.getElementById(id).innerHTML = value;
            }
        </script>
    </head>
    <body onload="load()">
        <table border="0" width="100%" cellspacing="0" cellpadding="0">
            <tr>
                <th>Availability:</th>
                <td id="availability"></td>
            </tr>
            <tr>
                <th>HostingBoard:</th>
                <td id="hostingBoard"></td>
            </tr>
            <tr>
                <th>InstallDate:</th>
                <td id="installDate"></td>
            </tr>
            <tr>
                <th>Manufacturer:</th>
                <td id="manufacturer"></td>
            </tr>
            <tr>
                <th>Model:</th>
                <td id="model"></td>
            </tr>
            <tr>
                <th>PartNumber:</th>
                <td id="partNumber"></td>
            </tr>
            <tr>
                <th>PNPDeviceID:</th>
                <td id="pnpDeviceID"></td>
            </tr>
            <tr>
                <th>PrimaryBusType:</th>
                <td id="primaryBusType"></td>
            </tr>
            <tr>
                <th>Product:</th>
                <td id="product"></td>
            </tr>
            <tr>
                <th>Removable:</th>
                <td id="removable"></td>
            </tr>
            <tr>
                <th>Replaceable:</th>
                <td id="replaceable"></td>
            </tr>
            <tr>
                <th>RevisionNumber:</th>
                <td id="revisionNumber"></td>
            </tr>
            <tr>
                <th>SecondaryBusType:</th>
                <td id="secondaryBusType"></td>
            </tr>
            <tr>
                <th>SerialNumber:</th>
                <td id="serialNumber"></td>
            </tr>
            <tr>
                <th>Status:</th>
                <td id="status"></td>
            </tr>
            <tr>
                <th>SystemName:</th>
                <td id="systemName"></td>
            </tr>
            <tr>
                <th>Version:</th>
                <td id="version"></td>
            </tr>
        </table>
    </body>
</html>


1 comment: