Using the Get-WindowsFeature PowerShell cmdlet is a far better option on Server 
OS:  1) the interface is consistent between Server 2008R2 and Server 2012; and 
2) the resulting PowerShell objects are much easier to reliably parse.

The only gotcha is that the C# wrapper needs to be compiled x64.  The 
ServerManager module can't be loaded into a 32-bit PowerShell.

--
John Merryweather Cooper
Build & Install Engineer - ESA
Jack Henry & Associates, Inc.®
Shawnee Mission, KS  66227
Office:  913-341-3434 x791011
jocoo...@jackhenry.com
www.jackhenry.com 



-----Original Message-----
From: Steven Ogilvie [mailto:steven.ogil...@titus.com] 
Sent: Wednesday, December 11, 2013 8:34 AM
To: General discussion about the WiX toolset.
Subject: Re: [WiX-users] Help activating IIS using the DISM command

One problem is that between the different versions of Windows the DISM command 
line parameters have changed...
I have created a custom action that checks what version of Windows I am running 
and then sets the command line parameters up accordingly...
Btw WriteErrorLogInstall is a custom logging function replace it with the 
session logging...

/// <summary>
        /// The check web server roles.
        /// </summary>
        /// <param name="session">
        /// The session.
        /// </param>
        /// <returns>
        /// The<see cref="ActionResult"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// throw new ArgumentNullException("session");
        /// </exception>
        [CustomAction]
        public static ActionResult CheckWebServerRoles(Session session)
        {
            var productName = string.Empty;
            try
            {
                if (session == null)
                {
                    throw new ArgumentNullException("session");
                }

                var tempString = GetSessionProperty(session, 
"CustomActionData", false);
                var parts = tempString.Split(new[] { '|' });
                productName = parts[0];

                var platformVersion = Environment.OSVersion.VersionString;

                var cmdLineParameters = string.Empty;
                if (platformVersion.Contains("6.1.760") && 
!Os.IsWindowsServer())
                {
                    // Windows 7
                    cmdLineParameters = "/Online /NoRestart /Enable-Feature 
/featurename:IIS-WebServerRole /featurename:IIS-CommonHttpFeatures 
/featurename:IIS-StaticContent /featurename:IIS-WebServerRole 
/featurename:IIS-ApplicationDevelopment /featurename:IIS-ISAPIFilter 
/featurename:IIS-ISAPIExtensions /featurename:IIS-NetFxExtensibility 
/featurename:IIS-ASPNET /featurename:IIS-WebServerRole 
/featurename:IIS-Security /featurename:IIS-RequestFiltering 
/featurename:IIS-WindowsAuthentication /featurename:WAS-ProcessModel 
/featurename:WAS-WindowsActivationService /featurename:WAS-NetFxEnvironment 
/featurename:WAS-ConfigurationAPI /featurename:NetFx3 
/featurename:WCF-HTTP-Activation";
                }
                else if (platformVersion.Contains("6.1.760") && 
Os.IsWindowsServer())
                {
                    // Windows Server 2008 R2
                    cmdLineParameters = "/Online /NoRestart /Enable-Feature 
/featurename:IIS-WebServerRole /featurename:IIS-CommonHttpFeatures 
/featurename:IIS-StaticContent /featurename:IIS-WebServerRole 
/featurename:IIS-ApplicationDevelopment /featurename:IIS-ISAPIFilter 
/featurename:IIS-ISAPIExtensions /featurename:IIS-NetFxExtensibility 
/featurename:IIS-ASPNET /featurename:IIS-WebServerRole 
/featurename:IIS-Security /featurename:IIS-RequestFiltering 
/featurename:IIS-WindowsAuthentication /featurename:NetFx3 
/featurename:WCF-HTTP-Activation";
                }
                else if (platformVersion.Contains("6.2.920") && 
!Os.IsWindowsServer())
                {
                    // Windows 8
                    cmdLineParameters = "/Online /NoRestart /Enable-Feature 
/featurename:IIS-WebServerRole /featurename:IIS-CommonHttpFeatures 
/featurename:IIS-StaticContent /featurename:IIS-ApplicationDevelopment 
/featurename:IIS-ISAPIFilter /featurename:IIS-ISAPIExtensions 
/featurename:IIS-NetFxExtensibility45 /featurename:IIS-ASPNET45 
/featurename:IIS-Security /featurename:IIS-RequestFiltering 
/featurename:IIS-WindowsAuthentication /featurename:NetFx4-AdvSrvs 
/featurename:NetFx4Extended-ASPNET45 /featurename:WCF-Services45 
/featurename:WCF-HTTP-Activation45 /All";
                }
                else if (platformVersion.Contains("6.2.920") && 
Os.IsWindowsServer())
                {
                    // Windows Server 2012
                    cmdLineParameters = "/Online /NoRestart /Enable-Feature 
/featurename:IIS-WebServerRole /featurename:IIS-CommonHttpFeatures 
/featurename:IIS-StaticContent /featurename:IIS-ApplicationDevelopment 
/featurename:IIS-ISAPIFilter /featurename:IIS-ISAPIExtensions 
/featurename:IIS-NetFxExtensibility45 /featurename:IIS-ASPNET45  
/featurename:IIS-Security /featurename:IIS-RequestFiltering 
/featurename:IIS-WindowsAuthentication /featurename:NetFx4 
/featurename:NetFx4Extended-ASPNET45 /featurename:WCF-Services45 
/featurename:WCF-HTTP-Activation45 /All";
                }

                var system32Directory = 
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), 
"system32");
                if (Environment.Is64BitOperatingSystem && 
!Environment.Is64BitProcess)
                {
                    // For 32-bit processes on 64-bit systems, 
%windir%\system32 folder
                    // can only be accessed by specifying %windir%\sysnative 
folder.
                    system32Directory = 
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), 
"sysnative");
                }

                // Windows 7 / 8 / 2008R2 / 2012
                var cmdLineExe = Path.Combine(system32Directory, "dism.exe");

                // Install Web Server features if missing
                var runDismInfo = new ProcessStartInfo
                {
                    UseShellExecute = true,
                    Arguments = cmdLineParameters,
                    FileName = cmdLineExe,
                    WindowStyle = ProcessWindowStyle.Hidden,
                    CreateNoWindow = true
                };

                // Run the external process & wait for it to finish
                using (var runDismProc = Process.Start(runDismInfo))
                {
                    runDismProc.WaitForExit();
                }
            }
            catch (Exception ex)
            {
                WriteErrorLogInstall(session, "CheckWebServerRoles failed: ", 
ex, true);
                if (session != null)
                {
                    session.Message(
                        InstallMessage.User + (int)MessageBoxIcon.Error + 
(int)MessageBoxButtons.OK,
                        new Record { FormatString = productName + " failed to 
install specific Web Server features\nException: " + ex.Message });
                }

                return ActionResult.Failure;
            }

            WriteSuccessLogInstall(session, "CheckWebServerRoles succeeded to 
install specific Web Server features...", true);
            return ActionResult.Success;
        }


/// <summary>
        /// The OS.
        /// </summary>
        private class Os
        {
            /// <summary>
            /// The OS ANYSERVER.
            /// </summary>
            [SuppressMessage("StyleCop.CSharp.NamingRules", 
"SA1310:FieldNamesMustNotContainUnderscore", Justification = "Reviewed. 
Suppression is OK here.")] // ReSharper disable InconsistentNaming
            private const int OS_ANYSERVER = 29; // ReSharper restore 
InconsistentNaming

            /// <summary>
            /// Prevents a default instance of the <see cref="Os"/> class from 
being created. 
            /// </summary>
            private Os()
            {
            }

            /// <summary>
            /// The is windows server.
            /// </summary>
            /// <returns>
            /// The <see cref="bool"/>.
            /// </returns>
            public static bool IsWindowsServer()
            {
                return IsOS(OS_ANYSERVER);
            }

            [DllImport("shlwapi.dll", SetLastError = true, EntryPoint = "#437")]
            private static extern bool IsOS(int os);
        }

-----Original Message-----
From: John Walter [mailto:jo...@twofold-software.com]
Sent: December-11-13 5:41 AM
To: WiX-users@lists.sourceforge.net
Subject: [WiX-users] Help activating IIS using the DISM command

Hi,

I am fairly new to the WiX installer but have been able to create an install 
package that creates our website and installs all needed components some being 
installed from other installers run from my bootstrapper.

The one element I am having difficulties with is enabling IIS. We need to have 
the ASPNET45 features enabled for our web page to operate so even if the IIS is 
enabled on the destination PC I need to check the features that are enabled. I 
can do this via the registry as each feature has an entry nd so can build a 
DISM command line that only enabled the missing features.

The problems I am having seem to come from inconsistencies with how the DISM 
command run. Sometimes there are no errors and IIS is up and running, sometimes 
I get error 0x800f0906 (this is concerning the source of the files needed for 
the features being enabled) and sometimes the IIS is installed but will only be 
running once the PC has been re-booted. The PC in all cases was a clean freshly 
installed version of Windows 8 (32-Bit) run as a virtual PC and reset after 
each attempt but using a snapshot so I am reasonably confident that the PC in 
all cases was the same.

Can anyone give me a clue as to where I can go from here as it seems the only 
way for me to get round this reliably would be to give detailed instructions as 
to how to enable IIS and what settings are required and get the user to 
activate manually and only check that the required features are turned on 
before installing the web site.


Example of the DISM command line

DISM /online /enable-feature /featurename:NetFx3 /featurename:NetFx4-AdvSrvs 
/featurename:NetFx4Extended-ASPNET45
/featurename:IIS-NetFxExtensibility45 /featurename:IIS-ASPNET45 /All

-- 

*John Walter*
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance affects 
their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & 
PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance affects 
their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & 
PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users
NOTICE: This electronic mail message and any files transmitted with it are 
intended
exclusively for the individual or entity to which it is addressed. The message, 
together with any attachment, may contain confidential and/or privileged 
information.
Any unauthorized review, use, printing, saving, copying, disclosure or 
distribution 
is strictly prohibited. If you have received this message in error, please 
immediately advise the sender by reply email and delete all copies.


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to