Skip to content
⌘ NSIS Forum Archive

Select Components based on OS

3 posts

hpnet#

Select Components based on OS

How can I select or deslect a component based upon the user's operating system?

Example - I have multiple components, the first is always required, and the rest are OS-dependant. The 3 OS-dependent components are marked with "/o" switch, I want the component to select itself, based upon the user's os.

> Package 1: Required
> Package 2: Windows 98 Only
> Package 3: Windows ME Only
> Package 4: Windows XP Only

I've tried using the GetWindowsVersion function, but I cannot use it outside of a function/component, and it does not seem to be able to add/remove the "/o" switch for me.

Any ideas?

Sample Code follows

Section "Application (Required)" SecApp
SectionIn RO
;Files, shortcuts, and the like...
SectionEnd

Section /o "System Files (98 Only)" SecWin98
;98-specific files
SectionEnd

Section /o "System Files (ME Only)" SecWinME
;ME-specific files
SectionEnd

Section /o "System Files (XP Only)" SecWinXP
;XP-specific files
SectionEnd
Afrow UK#
Here you go.
You just need to copy the Function .onInit code, !include Sections.nsh, and remove all /o from the Sections.

-Stu
hpnet#
Afrow UK,

Sorry for the slow reply, but thanks so much!

It worked like a charm, on the first try!
You truly are a lifesaver!

🙂 👍