Search code examples
directoryfilesystemobjectwindows-desktop-gadgets

Scripting.FileSystemObject location (from JavaScript)


I have a file for my Windows sidebar gadget that stores some settings for the user, but the FSO object seems to pick its native residence as the desktop, meaning that if I don't specify a directory, it will put this file on the desktop. I would specify the whole location, but I want to be able to put this on other people's computers without having stuff on their desktop or elsewhere besides the gadget folder.

I know this is possible in XMLHttpRequest, but I've had trouble with that in the past, and it would be better if I could just avoid it altogether, if possible.

function writeSetting(text)
{
    var fil = new ActiveXObject("Scripting.FileSystemObject");
    var writer = fil.OpenTextFile("loc.txt", 2, true);
    writer.WriteLine(text);
    writer.Close();

}

Solution

  • Use the System.Gadget.path property to get the gadget's path and append to it as needed. See the example in the link.

    Happy coding.