Hello,
Indeed, you are right, after some research I could also find out that the returned value must be "125" for LTSC.
First thing we have to do here is to create the PowerShell script. Please let me try to explain a bit here so you can better understand it. First of all, by running the following command:
gwmi win32_operatingsystem | select OperatingSystemSKU
we get the following result:
Code: Select all
OperatingSystemSKU
------------------
125
Let's say we want to condition something based on the result of the above cmdlet. First thing we would do will be to store the result of the above cmdlet in a variable. This can be done as it follows:
$ossku = gwmi win32_operatingsystem | select OperatingSystemSKU
Basically, if we wanted to condition anything based on that, we would write it as it follows:
if($ossku -eq "125"{
# do something
}
However, that would not work, because the returned type of the above cmdlet is not actually an integer nor a string, so the above comparison is wrong ("-eq "48"). By typing (in the current PowerShell session) the following:
$ossku.GetType()
we would notice that the $ossku is actually a PSCustomObject (PowerShell Custom Object). The correct way to retrieve the "125" value is like this:
$ossku.OperatingSystemSKU
With that being said, our condition should look something as it follows:
if($ossku.OperatingSystemSKU -eq "125"){
# do something
}
Now, in order to fail the installation based on the operating system SKU, we have two ways in which we can proceed:
1. you can implement this in an inline PS script custom action and then, based on the results, we can use our predefined "ErrorMessage" custom action - which displays a message to the user and then aborts the installation (this is the approach that I would recommend).
2. we can do all from above in a single PS script.
Since I would recommend the first approach, I will explain what steps need to be done in order to achieve it.
Now that we have our script ready, it is time to implement it into a custom action. Here is how you can proceed:
- open your project and go to
"Custom Actions" page.
- select a
"PowerShellScriptInline" custom action and press the
"Add custom action with sequence" button which is placed to the right side of the custom action's name.
- now we should schedule this custom action accordingly. Since we want it to execute at the starting point in our installation, we should schedule it before the
"Searches" action group - under
"Wizard Dialogs Stage". To do so, simply drag and drop it.
- the custom action's content should look something as it follows:
Code: Select all
# Block for declaring the script parameters.
Param()
# Your code goes here.
Add-Type -AssemblyName PresentationFramework
$ossku = gwmi win32_operatingsystem | select OperatingSystemSKU
if($ossku.OperatingSystemSKU -eq "125"){
# here we set the ABORT_INSTALL property to have the value "1" so we can further use it to condition the ErrorMessage custom action.
AI_SetMsiProperty ABORT_INSTALL 1
}
- under the
"Dialogs Stage Condition" section, you should uncheck the
"Uninstall" and
"Maintenance" checkboxes.
This is pretty much all about the PS script custom action. Now it is time to configure the "ErrorMessage" custom action. To do so, simply choose it from the list and then press the
"Add custom action with sequence" button which is located to the right side of the custom action's name. After doing so, it is time to schedule it accordingly. The earliest point in time where this custom action can be scheduled is after the
"Paths Resolution" action group (under
"Wizard Dialogs Stage"). With that being said, simply drag and drop it after the
"Paths Resolution" action group.
In the end, the custom actions should be scheduled as it follows:

- CA.PNG (15.06 KiB) Viewed 7152 times
Now that we have scheduled our "ErrorMessage" custom action, the only thing left is to set the message that you want to be shown to the user. Also, this custom action should be scheduled to run only during the installation process (by unchecking the
"Uninstall" and
"Maintenance" from under the
"Dialogs Stage Condition" section).
Hope this helps.
All the best,
Catalin
FOLLOW US
Get the latest news in Application Packaging