如何使用C#(或VB)安装IIS7?

时间:2013-04-19 03:09:00

标签: c# iis-7

我正在尝试以编程方式安装IIS7 +。如果我直接在cmd提示符下运行它,它运行正常。

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

由于开头的“开始”部分,我对如何运行ServiceProcess.Process类有点困惑。我可以运行我需要的任何其他exe,但pkgmgr.exe看起来不太好。

Using proc As New Process()
    proc.StartInfo.FileName = "c:\windows\system32\pkgmgr.exe"
    proc.StartInfo.Arguments = "/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"
    proc.Start()
    proc.WaitForExit()
End Using

1 个答案:

答案 0 :(得分:1)

我找到了这个值得信赖的链接Using Unattended Setup to Install IIS 7.0

第1步:PKGMGR.EXE概述

Windows使用名为Pkgmgr的新命令工具安装Vista / Windows Server 2008中的可选功能。使用pkgmgr.exe的命令行语法是:

Start /w pkgmgr.exe /iu:update1;update2… 

Pkgmgr.exe命令

/ iu:{更新名称}; 这指定了按更新名称安装的更新,并采用分号分隔的更新名称进行安装。

/ uu:{update name}; 这指定了要卸载的更新,并从系统中取出了以分号分隔的可选更新列表。必须至少指定一个更新名称

/ n:{unattend XML} 这指定了无人参与XML文件的文件名。

有关XML文件的更多详细信息,请参阅MSDN文章。


例如:

要仅安装IIS 7.0默认功能,请将以下unattend.xml文本复制到记事本中。

<?xml version="1.0" ?> 
<unattend xmlns="urn:schemas-microsoft-com:unattend"  
    xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
<servicing> 
   <!-- Install a selectable update in a package that is in the Windows Foundation namespace --> 
   <package action="configure"> 
      <ssemblyIdentity 
         name="Microsoft-Windows-Foundation-Package"
         version="6.0.5308.6"
         language="neutral"
         processorArchitecture="x86"
         publicKeyToken="31bf3856ad364e35"
         versionScope="nonSxS"
      />
    <selection name="IIS-WebServerRole" state="true"/> 
    <selection name="WAS-WindowsActivationService" state="true"/> 
    <selection name="WAS-ProcessModel" state="true"/> 
    <selection name="WAS-NetFxEnvironment" state="true"/> 
    <selection name="WAS-ConfigurationAPI" state="true"/> 
  </package> 
</servicing> 
</unattend>