In the end, I am trying to return the 'Product Version'
of Robocopy.exe
(in order to avoid using XP026; broken return code). I can use Shell.Application
, NameSpace
, ParseName
to get the 'Product Version', but I would need to know the NameSpace
(folder|directory|path) beforehand.
I can't write a NameSpace path into the script since it will run on different computers and Robocopy.exe could be in one or more directories listed in the system PATH environment variable. I am only interested in the ones found in PATH, and further, the instance that will execute as a result of the WScript.Shell
Run method. WScript.Shell Run
will execute the first instance found in the system search path when absolute path is not specified. That's the one I'm interested in finding.
My backup plan is to use the where.exe program to find the full path to Robocopy.exe
, return it to my vbs script using WScript.Shell Exec oExec.StdOut
and extract the path to use as NameSpace
in the code above.
I have been searching for a vbs or com control implementation of the winapi searchpath function/method and have had no luck. I'm surprised it's not already implemented in FileSystemObject
or Shell.Application
. I appreciate any help, referrals, or ideas.
To search the PATH variable for a given file you would have to get value of the variable, split it by the ";" character into an array and then loop through the array of directory paths checking each directory if contains the file you search for. But you can also use a CMD one-liner to achieve that: