1.

Solve : Set variable equal to part of a path?

Answer»

Squashman, thanks for the perspective. You made a good point. Salmon Trout I SUPPOSE I could have DONE that. I guess, like anything there are many different ways to arrive at the same destination. I'm not sure I if I even thought of doing it that way though. I recall getting hung up on how to set parts of the file path equal to different variables.

After posting here I broke down the commands I had for determining the installed version of Office so I could learn a little more. What I found is that the command (12 lines) was overkill and liked the idea of querying the registry instead of rewriting what I had.

But after Salmon Trout mentioned that his Windows registry didn't include the InstallRoot key I became CONCERNED - every machine I tested on had the key but when I first wrote this script it ran well on every machine I tested it on. It wasn't until we released the script into production that we learned that there were servers that wouldn't run it properly (different problem). So rather than take a chance on the InstallRoot key and because the registry query took a short while longer to return results than the ftype command I did a complete turnabout and looked through some of my notes to FIND the syntax for stripping characters from a string.

This is what I'm going to use:

Code: [Select]FOR /f "tokens=2 delims==" %%O in ('ftype ^|findstr /r /I "\\OFFICE[0-9]*" 2^>nul') DO SET "verp=%%O"
SET OFFPATH=%verp:~1,-20%
SET OFFVER=%verp:~35,-21%
This gives me the Office path and version.

Thanks for all of the help guys. I always learn SOMETHING when I ask for help here.

MJQuote from: powlaz on January 23, 2014, 02:51:48 PM

But after Salmon Trout mentioned that his Windows registry didn't include the InstallRoot key I became concerned - every machine I tested on had the key but when I first wrote this script it ran well on every machine I tested it on.

This is all I have under HKLM\Software\Microsoft\Office - one key: Outlook



Quote from: powlaz on January 23, 2014, 11:43:37 AM
because I often write out my commands line by line and then work to shorten them to as few lines as possible.

I noticed your shortened the code I gave you.

There are often bits of code that don't seem to do anything when you remove them, but they fix issues when the code is used on other machines.Quote from: powlaz on January 23, 2014, 12:08:35 PM
I wonder if you have the key under the WOW6432Node key.

Yes. That is where it is stored. I have 32 bit Office 2003 on 64 bit Windows 7.

Foxidrive, I did wonder why you had included those couple of extra find statements. What did you see that I didn't?

The statement I said I was going to use last time I posted yielded mixed results. When I first composed this reply over a week ago I was planning on changing to using a directory search like Salmon Trout suggested - but it ran too slowly. Then I decided to use the reg query that we had discussed and that's how I was going to leave it.

However, I was drawn into another project that required me to find the install directory for Adobe Reader. A slight tweak to the "ftype" statement proved to provide much better/faster results. So I modified it for my Office search:

Code: [Select]For /f "tokens=2 delims==" %%a in ('ftype ^|find /I "C:\Program" ^|findstr /I "excel.exe"')DO SET Office=%%a
Set OfficePATH=%Office:~1,-10%
This returns results the fastest and eliminates the erroneous results I was getting earlier.

Again, I really appreciate all the replies here. I learned a lot.

MJ


Discussion

No Comment Found