最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

windows desktop gadgets - Find %LocalAppData% path and add new folder with JavaScript - Stack Overflow

programmeradmin2浏览0评论

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();
发布评论

评论列表(0)

  1. 暂无评论