c# - Better way to install IIS7 programmatically -
i have webapp installer installs of prerequisites, includes iis 7 too.
since iis doesn't come prerequisite in visual studio setup project, came following code install iis code (targeting windows vista , 7).
private string configureiis7() { string output = string.empty; if (environment.osversion.tostring().contains("microsoft windows nt 5")) // windowsxp [with or without sp2] { messagebox.show("iis 6.0 not installed on machine. please install same , proceed installation or contact administrator","installer",messageboxbuttons .ok ,messageboxicon .warning); throw new system.exception("iis 6.0 not installed on machine."); } else { string cmdtoexecute; cmdtoexecute = "cmd /c start /w pkgmgr /l:log.etw /iu:iis-webserverrole;iis-webserver;iis-commonhttpfeatures;iis-staticcontent;iis-defaultdocument;iis-directorybrowsing;iis-httperrors;iis-httpredirect;iis-applicationdevelopment;iis-aspnet;iis-netfxextensibility;iis-asp;iis-cgi;iis-isapiextensions;iis-isapifilter;iis-serversideincludes;iis-healthanddiagnostics;iis-httplogging;iis-logginglibraries;iis-requestmonitor;iis-httptracing;iis-customlogging;iis-security;iis-basicauthentication;iis-urlauthorization;iis-requestfiltering;iis-ipsecurity;iis-performance;iis-httpcompressionstatic;iis-httpcompressiondynamic;iis-webservermanagementtools;iis-managementconsole;iis-managementscriptingtools;iis-managementservice;iis-iis6managementcompatibility;iis-metabase;iis-wmicompatibility;iis-legacyscripts;iis-legacysnapin;was-windowsactivationservice;was-processmodel;was-netfxenvironment;was-configurationapi"; process prruniis = new process(); prruniis.startinfo = new processstartinfo("cmd.exe", cmdtoexecute); prruniis.startinfo.useshellexecute = false; prruniis.startinfo.redirectstandardoutput = true; prruniis.startinfo.createnowindow = true; prruniis.start(); prruniis.waitforexit(); output = prruniis.standardoutput.readtoend(); } return output; }
this code has worked far. concern installation part takes considerable amount of time.
now, have opportunity rewrite of codes , alter installer ui. came part , wondered if solution install iis code, or there may better way haven't found?
i curious know other ways install iis. answers targeted windows 8 appreciated.
the best option going forward using dism (deployment image servicing , management). works on windows 7
/windows server 2008 r2
, above. other options deprecated.
here's code sample minimum features needed (you can add more if require different ones):
string setupiis() { var featurenames = new [] { "iis-applicationdevelopment", "iis-commonhttpfeatures", "iis-defaultdocument", "iis-isapiextensions", "iis-isapifilter", "iis-managementconsole", "iis-netfxextensibility", "iis-requestfiltering", "iis-security", "iis-staticcontent", "iis-webserver", "iis-webserverrole", }; return processex.run( "dism", string.format( "/norestart /online /enable-feature {0}", string.join( " ", featurenames.select(name => string.format("/featurename:{0}",name))))); }
static string run(string filename, string arguments) { using (var process = process.start(new processstartinfo { filename = filename, arguments = arguments, createnowindow = true, windowstyle = processwindowstyle.hidden, redirectstandardoutput = true, useshellexecute = false, })) { process.waitforexit(); return process.standardoutput.readtoend(); } }
this result in following command:
dism.exe /norestart /online /enable-feature /featurename:iis-applicationdevelopment /featurename:iis-commonhttpfeatures /featurename:iis-defaultdocument /featurename:iis-isapiextensions /featurename:iis-isapifilter /featurename:iis-managementconsole /featurename:iis-netfxextensibility /featurename:iis-requestfiltering /featurename:iis-security /featurename:iis-staticcontent /featurename:iis-webserver /featurename:iis-webserverrole
Comments
Post a Comment