我有一个 webapp 安装程序,它安装了它的所有先决条件,其中也包括 IIS 7。
由于 IIS 不是 Visual Studio 安装项目的先决条件,因此我想出了以下代码来从代码安装 IIS(针对 Windows Vista 和 7)。
private string ConfigureIIS7()
{
string output = string.Empty;
if (Environment.OSVersion.ToString().Contains("Microsoft Windows NT 5")) // Its WindowsXP [with or without SP2]
{
MessageBox.Show("IIS 6.0 is not installed on this machine. Please install the same and proceed with the installation or contact your administrator","Installer",MessageBoxButtons .OK ,MessageBoxIcon .Warning);
throw new System.Exception("IIS 6.0 is not installed on this 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;
}
到目前为止,此代码运行良好。我唯一担心的是安装部分需要相当长的时间。
现在,我有机会重写一些代码并更改安装程序 UI。我刚刚来到这部分,想知道这是否是从代码安装 IIS 的唯一解决方案,或者是否有更好的方法我还没有找到?
我只是想知道安装 IIS 的其他方法是什么。还感谢针对 Windows 8 的答案。