There are various COM objects available to JScript using the ActiveXObject
class. You can write your own interop assembly using .NET but this introduces several problems:
- Each public class within the assembly needs be registered on the host machine before use. There are problems posed when writing to and creating keys in x64, which the WScript.Shell object struggles with for certain parts of the registry. WMI works well for registering, however.
- From instantiation, the assembly dll is locked and cannot be deleted even if the gadget is closed. This is mostly an issue when uninstallation/software updates come into play. Once the sidebar.exe process is ended, the file becomes unlocked.
- Unregistering seems to be problematic, even with WMI. Timing the unregistration is often an issue (do you do it on unload or after instantiation? What if there are multiple gadgets open using it?). Also, not unregistering will leave unwanted registry keys on the user's machine if he/she decides not to keep your gadget.
- If the gadget relies 100% on the assembly and, for whatever reason, the assembly cannot be registered on the user's machine then the entire experience of the gadget is unavailable to that user. Be prepared for some low rated reviews on Windows Live Gallery.
If you decide you really need to write an assembly. I would advise that if you are writing your own assembly for a gadget that it is an extension to the basic functionality of your gadget and that you ensure the gadget has features available should the user be unable to use the assembly.
My company has an as-of-yet unreleased solution to the above issues which we are planning on making available to all Windows Desktop Gadget developers in the near future (ie after more testing).
As for the advanced features you specified, these can all be done using some built-in Windows COM objects, which are already registered and aren't distributed with your gadget so they don't suffer the same issues noted above. As an answer to your specific requirements, examples of these are:
FileSystemObject
Writing/Reading files can be done using FileSystemObject. A basic example of FileSystemObject for reading files is:
var ForReading = 1, ForWriting = 2, ForAppending = 8;
var oFSO = new ActiveXObject("Scripting.FileSystemObject");
var oFile = oFSO.OpenTextFile(System.Gadget.path+"\\test.txt", ForReading, true);
var sText = oFile.ReadAll();
window.prompt("", sText);
Windows Management Instrumentation (WMI)
WMI has an enourmous range of purposes. Certain parts of it will require administrative rights, though (which must be applied to sidebar.exe). One of the classes within WMI is Win32_Process which can be used to iterate through running processes. Note that it's much more difficult to use WMI in JScript than it is in VBScript and most examples you find on the internet are for VBScript (which makes porting the code a pain).
Windows Script Host Shell
The WshShell Object provides another great extension to the limitations of Windows Desktop Gadgets, including the SendKeys method. Although the method cannot be used to send a key to an application specifically, it's possible to activate the application with the AppActivate method and then use SendKeys to emulate keystrokes in the activated application.
I hope that helps :-)