问题
I have an installer that runs a CustomAction which runs an embedded powershell script to test for the installed status of various required windows features. This works correctly but it is terribly slow to complete.
Is there an alternative method to test for such features? I expect there to be something along the lines of registry keys for each feature and sub-feature but I have not found any documentation on the subject.
回答1:
In one of the installation projects we used dism.exe to enable required Windows features.
For example, enabling ASP.NET in IIS 8 was done with the following custom action:
<!-- 32-bit edition of Windows knows where to find dism.exe -->
<Property Id="DISMEXEPATH" Value="dism.exe" />
<!-- 64-bit edition of Windows requires this workaround to get proper dism.exe version -->
<SetProperty Id="DISMEXEPATH" Value="[WindowsFolder]Sysnative\dism.exe" After="AppSearch">VersionNT64</SetProperty>
<!-- And the CA to do the job (with the help of [quiet execution CA][2]) -->
<CustomAction Id="SetForEnableAspNetIIS8" Property="EnableAspNetIIS8" Value=""[DISMEXEPATH]" /norestart /quiet /online /enable-feature /featurename:IIS-ApplicationDevelopment /featurename:IIS-ASPNET45 /featurename:IIS-NetFxExtensibility45 /featurename:NetFx4Extended-ASPNET45 /featurename:IIS-ISAPIExtensions /featurename:IIS-ISAPIFilter" />
<CustomAction Id="EnableAspNetIIS8" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check"/>
This doesn't seem to be a good practice, but it worked for that project.
回答2:
I ended up using a (now deleted) suggestion to use a managed DTF custom action to query for server features in C#.
[CustomAction]
public static ActionResult CheckFeatures(Session session)
{
SelectQuery q = new SelectQuery("Win32_ServerFeature");
ManagementObjectSearcher s = new ManagementObjectSearcher(q);
foreach (ManagementObject e in s.Get())
{
if((UInt32)e["ID"] == FeatureId)
{
session["FeatureIsSet"] = "1";
}
}
}
<CustomAction Id="CACheck" BinaryKey="CA" DllEntry="CheckFeatures"
Execute="immediate" Return="check" />
<Binary Id="CA" SourceFile="path/to/bin" />
来源:https://stackoverflow.com/questions/18992363/test-for-windows-features