You can obtain detailed information about the processors and power status on your system with the following objects:
System.Machine.CPU and System.Machine
object contains information about the CPU of the computer running the gadget. The System.Machine
object exposes a collection of System.Machine.CPU
objects through its System.Machine.CPUs
The following code example displays the detailed information of the current machine hosting the gadget and then displays the name and usage percentage for each CPU (in a multicore processor).
var result = document.getElementById("result");
result.innerHTML = "Available Memory: " +
System.Machine.availableMemory + "MB<br/>";
result.innerHTML += "Total Memory: " +
System.Machine.totalMemory + "MB<br/>";
result.innerHTML += "Processor Architecture: " +
System.Machine.processorArchitecture + "<br/>";
//---get all CPUs---
var cpus = System.Machine.CPUs;
//---display name and usage of each CPU---
for (i=0; i<cpus.count; i++)
result.innerHTML += "<b>" + cpus.item(i).name +
result.innerHTML += cpus.item(i).usagePercentage +
cpus = null;
result = null;
shows the result when the gadget is run on my computer.
|Figure 4. Running the Gadget: Displaying the detailed information of a system.|
The System.Machine.PowerStatus object returns detailed information about the power status of the computer hosting the gadget.
The System.Machine.PowerStatus object has one event, powerLineStatusChanged, which specifies a function that is called whenever the system is switched from adapter power to battery power, or vice versa.
The gadget in Listing 5 shows the detailed power status of your computer. When the page is loaded, you first print out the power status of your computer. You then set the powerLineStatusChanged event to the PowerLineStatusChanged event handler so that this event handler will be called whenever there is a change in power status (such as when you switch from battery power to adapter power, and vice versa).
The PowerLineStatusChanged() function is fired whenever there is a change in power status (such as the notebook computer is connected to a power source).
This article has examined the first four objects exposed by Windows Sidebar. Stay tuned for Part 2, which will discuss the email, network, sound, and time and time zone objects.