Checkfileage does not work when file names use {}
If you have a file name containing the curly braces characters {} then checkfileage will not work.
For example, testing the file age of the following file:
C:/Program Files/HP/{E94E150C-762B-4cd1-8A54-7228A07C0710}/scrubber.exe
check_wmi_plus.pl -H HOST -u USER -p PASS -m checkfileage -a "C:/Program Files/HP/{E94E150C-762B-4cd1-8A54-7228A07C0710}/scrubber.exe"
Results in:
UNKNOWN - Could not find the file C:/Program Files/HP/{E94E150C-762B-4cd1-8A54-7228A07C0710}/scrubber.exe
If you look at the debug output (add -d to the command line) you will notice that the actual WMI query used is:
Select name,lastmodified from CIM_DataFile where name="C:\\Program Files\\HP\\\\scrubber.exe"
Notice that the {E94E150C-762B-4cd1-8A54-7228A07C0710}
part of the file name is actually totally missing.
This is because the use of { } is used internally to Check WMI Plus for signifying parameter substitution. That is, the WMI query in the code is coded to use command line argument 1 as the filename. It is specified in the WMI query as {_arg1} and a regular expression is used to look in the coded WMI query to substitute command line parameters into place before execution. So when {E94E150C-762B-4cd1-8A54-7228A07C0710} is specified in the filename Check WMI Plus looks for a parameter “E94E150C-762B-4cd1-8A54-7228A07C0710”, which returns nothing so “{E94E150C-762B-4cd1-8A54-7228A07C0710}” is replaced with nothing ie deleted.
Check WMI Plus variable substitution is used extensively within ini files. It is documented in samples.ini
.
Fortunately there is a workaround you can do to make this all work. Ironically, it is actually using parameter substitution.
For the above example, if we add a third command line parameter (we can do this since its not used for anything else by checkfileage) containing part of the filename, we can actually substitute this into the filename we are actually looking for. Here’s the example to help explain it:
Change the filename we are looking for to use a command line substitution variable for arg3.
Then set arg3 to be the missing part of the file name, {E94E150C-762B-4cd1-8A54-7228A07C0710}.
Like this:
check_wmi_plus.pl -H HOST -u USER -p PASS -m checkfileage -a "C:/Program Files/HP/{_arg3}/scrubber.exe" -3 "{E94E150C-762B-4cd1-8A54-7228A07C0710}"
Now before the WMI query runs, {_arg3} is replaced by {E94E150C-762B-4cd1-8A54-7228A07C0710} and we get our file name back!