Test for Windows Features

白昼怎懂夜的黑 提交于 2020-01-14 05:57:08

问题


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="&quot;[DISMEXEPATH]&quot; /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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!