Problem
Using the well known environment variables like %programfiles%
, programfiles(x86)
does not workout anymore, because:
- XP does not know the
programfiles(x86)
variable
programfiles
refers to the x86 or x64 folder, based on the architecture of
the machine. (Or more specific: To the architecture of the process calling the variable)
- For XP, the name of the 32-bit-folder is localized (I.e.
C:\Programme (x86)
for a german XP, running x64)
Assuming, that there are 2 languages, 2 OS Types (7,10 behave equal regarding "type") and 2 architecture types, the following Options are possible with "native" Tools, but it is already clumsy:
To create a shortcut to the "highest" version, you need to deploy 3 Shortcut "rules":
Shortcut |Target | Purpose
App |%programfiles%\App\app.exe | x86-app on a x86-xp-7-10 or
| | x64-app on a x64-xp-7-10
App |%programfiles(x86)%\App\app.exe | x86-app on a x64-7-10
App |C:\Programme (x86)\App\app.xe | x86-app on a x64-xp (german)
Assuming, you also want to enable the possibility of every application beeing available as x86 and x64 at the same time, it gets even worse, because: %programfiles%
will lead to wrong results (it could be either x86 or x64) - So you need WMI-Filters on every "shortcut" beeing created to handle this.
A rule like this:
Shortcut |Target | Purpose
App 64 |%programfiles%\app\app.exe | x64-app on a x64-7-10
would accidently link the 32 bit version
on 32-bit-systems
with the name x64
- without some WMI-Filter, deactivating the rule.
So it would be 4 rules, 2 with WMI-Filters:
Shortcut |Target | Purpose
App 64 |%programfiles%\App\app.exe | x64-app on a x64-xp-7-10 + wmi-filter
App 32 |%programfiles%\App\app.exe | x86-app on a x86-xp-7-10 + wmi_filter
App 32 |%programfiles(x86)%\App\app.exe | x86-app on a x64-7-10
App 32 |C:\Programme (x86)\App\app.xe | x86-app on a x64-xp (german)
So - 240 shortcut rules, if there is only one "foreign language" - But there where 5 of them -> 480 error prone shortcut rules. -> Nope!
The Goal
I wanted to be able to reduce the amount of work required. Just creating (worst-case) 2 entries per shortcut, stating:
- This application can be available anywhere, as 32-bit version.
- This application can be available on 64-bit machines only, as 64 bit version.
Custom Environment Variables by GPO, using WMI Filters
As a solution to this question, I've created 1 GPO to create the required custom Environment-Variables:
Variable | Purpose
%pf_x86% | Program Files x86 on any system
%pf_x64% | Program Files x64 on any system (if existing)
So, this (single GPO) comes down to a total of 6 rules (+1 for every additional language of XP):
Variable | Value | OS | WMI Filter (Item-Level-Targeting):
%pf_x86% | %programfiles% |7 x86 | select * from Win32_OperatingSystem
WHERE Version like "6.%" AND
ProductType="1" AND
NOT OSArchitecture = "64-bit"
%pf_x86% | %programfiles(x86)% |7,10 x64| select * from Win32_OperatingSystem
WHERE (Version like "6.%" OR
Version like "10.%") AND
ProductType="1" AND
OSArchitecture = "64-bit"
%pf_x86% | %programfiles% |XP x86 | select * from Win32_OperatingSystem
WHERE (Version like "5.1%") AND
ProductType="1"
%pf_x86% | C:\Programme (x86) |XP x64 | select * from Win32_OperatingSystem
WHERE (Version like "5.2%") AND
ProductType="1" AND OSLanguage=1031
%pf_x64% | %programfiles% |7,10 x64| select * from Win32_OperatingSystem
WHERE Version like (Version like "6.%" OR
Version like "10.%") AND
ProductType="1" AND
OSArchitecture = "64-bit"
%pf_x64% | %programfiles% |XP x64 | select * from Win32_OperatingSystem
WHERE (Version like "5.2%") AND
ProductType="1"
(OS Languages are outlined here: https://www.autoitscript.com/autoit3/docs/appendix/OSLangCodes.htm)

Outcome
This custom environment variable now allows me to configure exactly two shurtcuts per application - No matter which OS-Version is running on whatever architecture or language
Shortcut |Target | Purpose
App 64 |%pf_x64%\App\app.exe | x64-app on any environment.
App 32 |%pf_x86%\App\app.exe | x86-app on any environment.
And if both exist - both shortcuts will be deployed.
Windows 7, 64bit, ML

Windows 7, 32bit, ML

Windows XP, 32 bit, ger

etc. pp.