Chrome - how to verify an extension state

Chrome extensions status information are stored in the "Preferences" file under this path: %userprofile%\AppData\Local\Google\Chrome\User Data\Default.

 

It's possibile to retrieve the activation/deactivation status of an extension reading some informations from string sequences. Here we try to use some regular expressions that allow us to generalize some dynamic informations inside contexts with particular characteristics. 

 

Let's see an example:

In our Preferences file we can find these strings:

"path":"pjkljhegncpnkpknbcohdijeoejaedia\\8.2_1","preferences":{},"regular_only_preferences":{},"state":0

"path":"kglbdihdcnciobeihioplammnkknjmbd\\15.0.2.3123_0","preferences":{},"regular_only_preferences":{},"state":1

 

As we can see there are keys and related values. In our case we will start from the extension ID, the very long alphabetical value that you can easily see in the chrome://extensions/ page.

 

The structure follows this pattern: 

ID+\\\\[\d-\.\_]{1,}\W{1,}\w{1,}\W{1,}\{\}\W{1,}\w{1,}\W{1,}\{\}\W{1,}\w{1,}\W{1,}\d{1}

I'm quite sure this could be better define. RegExp is one of the worst argument for developers, ouch!

 

 

Let's see the code that retrieve a sting like Active or Not Active for the extension.

 

'Program to check Extension Chrome State

'Information about chrome extensions are under %userprofile%\AppData\Local\Google\Chrome\User Data\Default into Preferences file

 

'Const CHRM_EXT_ID    = "pjkljhegncpnkpknbcohdijeoejaedia"   'Extension ID

Const CHRM_EXT_ID    = "kglbdihdcnciobeihioplammnkknjmbd"   'Extension ID

Const CHRM_STD_PATTERN = "\\\\[\d-\.\_]{1,}\W{1,}\w{1,}\W{1,}\{\}\W{1,}\w{1,}\W{1,}\{\}\W{1,}\w{1,}\W{1,}\d{1}"

 

Const CHRM_PATH    = "\AppData\Local\Google\Chrome\User Data\Default\"

Const CHRM_PREF_FILE   = "Preferences"

 

'Creation of objects to interact with file and to read the value of %userprofile% environment variable

 

Dim fso : set fso = createobject("Scripting.FileSystemObject")

Dim myShell : set myShell = WScript.CreateObject("WScript.Shell")

 

 

'definition and initialization of the variable that will contain the value of the environment variable

 

Dim usrProfPath : usrProfPath = myShell.ExpandEnvironmentStrings("%userprofile%") 

 

'message that give us the information we need.

wscript.echo "Status of " & CHRM_EXT_ID & " is: " & ReadChromeExtensionStatus(CHRM_EXT_ID, CHRM_STD_PATTERN)

 

set myShell = nothing           

set fso = nothing

 

wscript.quit

 

 

 

'CORE: this function returns a string ("Active|NotActive") about the state of the plugin (0=NotActive, 1=Active)

 

Function ReadChromeExtensionStatus(plugin, ptrn)

 

Dim strRes : strRes = "Not Active" 'return value of the function - default is "Not Active"

Dim PATTERN_CHROME  : PATTERN_CHROME = plugin & ptrn 'this is the complete pattern to use for the Regular Expression test

 

 

dim RE : set RE = CreateObject("VBScript.RegExp") 'Regular Expression object

dim colMatch 'the match collection

 

 

'Open the file Preferences for reading

Dim myFile : set myFile = fso.opentextfile(usrProfPath & CHRM_PATH & CHRM_PREF_FILE, 1)

 

'Create the loop to read the file

Do while not(myFile.AtEndOfStream)

tmpLine = myFile.ReadLine  'it is a looong line 

with RE

.Pattern = PATTERN_CHROME

.IgnoreCase = True

.Global     = True

end with

 

if (RE.Test(tmpLine)) then 'I test if in the line there is almost a match 

set colMatch = RE.Execute(tmpLine) 'load the collection

 

for m=0 to colMatch.Count-1  'Do a for cycle for each match (there should only be one match)

'the colMatch.Item(0).Value returns all the string, but I need only the last value (0/1)

 

if int(right(colMatch.Item(m).Value,1)) = 1 then

strRes = "Active"  'update the result

end if

 

next

 

end if

Loop

  

myFile.close

set myFile = nothing

 

ReadChromeExtensionStatus = strRes  'return the value

End Function

 

Pag: <<   <    >   >>