Search code examples
componentswindows-desktop-gadgets

Can I embed an external component in a Windows 7 gadget?


Some features I needed is not available in the Javascript API. Is it possible to use an external component (C++ or whatever) in a gadget? In particular, I'd like to get a list of running processes.


Solution

  • You can access WMI objects (or pretty much any COM object) from a gadget. For example the following WMI JScript will dump all processes on the system to the gadget window (put it in the HTML).

    try {
        var wmi = GetObject("winmgmts:\\\\.\\root\\CIMV2");
        var items = wmi.ExecQuery("SELECT * FROM Win32_Process");
        var i = 0;
    
        while(i < items.Count)
        {
             var item = items.ItemIndex(i);
             document.writeln(item.Name);       
             i++;
        }
    } catch(e) {
        document.write(e.message);
    }