admin管理员组

文章数量:1406921

I created a Windows 7 Gadget and I need to create a place on each user's puter to store the Settings.ini file (Created from my SettingsManager.js file). The application packaging team at my pany remends I use

%LOCALAPPDATA%\Microsoft\Windows Sidebar\

and then add

Gadgets\iMon.Gadget\

subfolders. This is so each user's settings are stored in a unique location and won't be changed by any other applications or gadgets.

Do I need to use something along the lines of

var fso = new ActiveXObject("Scripting.FileSystemObject");
var folder = fso.CreateFolder("path");

Any help on how to do this would be appreciated.

Update: I found how to get the %localappdata% path, but I still need to create the new folder. Here's what I've tried without success:

var wshshell = new ActiveXObject("wscript.shell");
var localAppData = wshshell.ExpandEnvironmentStrings("%localappdata%");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";

I created a Windows 7 Gadget and I need to create a place on each user's puter to store the Settings.ini file (Created from my SettingsManager.js file). The application packaging team at my pany remends I use

%LOCALAPPDATA%\Microsoft\Windows Sidebar\

and then add

Gadgets\iMon.Gadget\

subfolders. This is so each user's settings are stored in a unique location and won't be changed by any other applications or gadgets.

Do I need to use something along the lines of

var fso = new ActiveXObject("Scripting.FileSystemObject");
var folder = fso.CreateFolder("path");

Any help on how to do this would be appreciated.

Update: I found how to get the %localappdata% path, but I still need to create the new folder. Here's what I've tried without success:

var wshshell = new ActiveXObject("wscript.shell");
var localAppData = wshshell.ExpandEnvironmentStrings("%localappdata%");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";
Share Improve this question edited Aug 12, 2010 at 13:14 Mark Cheek asked Aug 12, 2010 at 12:56 Mark CheekMark Cheek 2652 gold badges10 silver badges20 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

I'm not sure I understand what you're trying to do here. is iMon.Gadget the name of your gadget? If so, this folder is automatically created for you upon installation of the gadget when the .gadget archive is executed. All the gadget's files and folders will be unpacked to

%LOCALAPPDATA\Microsoft\Windows Sidebar\Gadgets\iMon.gadget\

In your code, you can then proceed to manipulate files within this folder (and it's subfolders). To get the full path, you use

var gadgetPath = System.Gadget.path;

For example:

var oFile,
    gadgetPath = System.Gadget.path,
    oFSO = ActiveXObject("Scripting.FileSystemObject");

oFile = oFSO.CreateTextFile(gadgetPath + "\\test.txt", true);
oFile.WriteLine("Test.");
oFile.Close();

本文标签: windows desktop gadgetsFind LocalAppData path and add new folder with JavaScriptStack Overflow