How do you know those segments will always be correct?
because that's how office installs? the appPath you are reading might exist in windows vista. or might not. should not exist in anything earlier. and you are still looking for an office application, not office.
so if you have custom install with word excluded because the installer hated it, your script would not see office.
now, I know my sku matching is not complete and I might improve it or just put a disclaimer that office older than 2007 is not supported.
the point still does come back to the "boys and girls" comment earlier. if it supposedly is so easy, why it takes many brains and days and still isn't done reliably?
and if we turn this around, it took me the whole 30 minutes to write an udf, test it and post it... well, maybe closer to an hour. I would say the UDF was thus easier and simpler than "simple batch script"