As part of a Windows logon script (hence the VBScript requirement), I would like to set values in a user's Google Chrome preferences (stored in a JSON file in the user profile) to apply download settings when they logon.
I'm trying to achieve the following:
- Open a JSON file (
%userprofile%Local SettingsApplication DataGoogleChromeUser DataDefaultPreferences
) and read the contents to a string;
- Search for a particular node named "download", which by is pre-populated with multi-line values that may vary between builds;
- Replace the entire text between the braces with specified multi-line text; and
- Write the updated string to the original file and save.
The full JSON file is fairly large, but as a sample to use as the input, this is copied from a typical Google Chrome prefs JSON file:
"bookmark_bar": {
"show_on_all_tabs": false
},
"download": {
"directory_upgrade": true,
"prompt_for_download": false
},
"sync": {
"suppress_start": true
},
I would like to programmatically search for the "download" node, and replace everything between the braces of just this node so that it reads:
"download": {
"default_directory": "C:\Windows\Temp",
"extensions_to_open": "pdf",
"prompt_for_download": false
},
...with the rest of the file's contents unchanged.
Given the whitespace and multiple lines in the section of the JSON to be replaced, as well as the wildcard requirement to include all/any text between the braces, I can't do this using the VBScript Replace function, but my RegEx knowledge is limited.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…