0

I'm trying to edit a json file which is located inside a folder in AppData\Roaming.

The file path is AppData\Roaming\Myapp\RANDOM_CRAP\settings.json

RANDOM_CRAP is just a random folder name which is different for every machine. In order to open this file for writing, I first tried to get it's file path, like so:

function getAppData() {
   var oShell = new ActiveXObject("WScript.Shell");
   var strValue = oShell.RegRead("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\\AppData");
   return strValue;
}

Problem is, the value stored under that registry key is %USERPROFILE%\AppData\Roaming which doesn't seem to open with:

var folder = fso.GetFolder(getAppData());

(Throws Path not found error)
Can I get to the APPDATA path in another way?

user1555863
  • 2,567
  • 6
  • 35
  • 50

1 Answers1

0

Getting to AppData path is easy with the ExpandEnvironmentStrings Method.

Party time:

var WshShell = WScript.CreateObject("WScript.Shell");
WScript.Echo("WinDir is " + WshShell.ExpandEnvironmentStrings("%AppData%"));

Good luck.

user1555863
  • 2,567
  • 6
  • 35
  • 50