使用dism從命令列安裝IIS

秦秋隨發表於2022-10-25

參考Windows2008 2012 2016 2019 IIS7.5 8.0 10.0 一鍵安裝指令碼BAT安裝指令碼釋出 - 筆戈 (biger.me),使用DISM重新實現

技巧:

可先手工安裝IIS各項功能後,在命令列中使用dism /online /get-features >f.txt 得到各項功能的名稱,然後在指令碼中針對性的啟用或禁用

@@@code

 

部署映像服務和管理工具

版本: 6.3.9600.17031

 

映像版本: 6.3.9600.17031

 

程式包功能列表 : Microsoft-Windows-Foundation-Package~31bf3856ad364e35~amd64~~6.3.9600.16384

 

功能名稱 : Microsoft-Hyper-V-All

狀態 : 已禁用

 

功能名稱 : Microsoft-Hyper-V-Tools-All

狀態 : 已禁用

 

功能名稱 : Microsoft-Hyper-V

狀態 : 已禁用

 

功能名稱 : Microsoft-Hyper-V-Management-Clients

狀態 : 已禁用

 

功能名稱 : Microsoft-Hyper-V-Management-PowerShell

狀態 : 已禁用

 

功能名稱 : Printing-Foundation-Features

狀態 : 已啟用

 

功能名稱 : Printing-Foundation-LPRPortMonitor

狀態 : 已禁用

 

功能名稱 : Printing-Foundation-LPDPrintService

狀態 : 已禁用

@@#

 

@@@code

@echo off

title IIS一鍵安裝指令碼

color 5e

rem mode con cols=30 lines=5

rem 2008 r2 or win7

ver | find "6.1.7600" > NUL && goto :win2008

rem 2008 r2 sp1 or win7 sp1

ver | find "6.1.7601" > NUL && goto :win2008

rem 8.1 or 2012

ver | find "6.3.9600" > NUL && goto :win2012

rem 2016

ver | find "10.0.14" > NUL && goto :win2012

rem 2019

ver | find "10.0.17" > NUL && goto :win2012

rem 10

ver | find "10.0.19" > NUL && goto :win2012

echo 無法識別當前系統版本,進行預設安裝

ver

goto :win2012

pause

exit

 

:win7

rem pkgmgr方式

echo 正在安裝IIS這可能需要幾分鐘...

start /w pkgmgr /iu:IIS-WebServerRole;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI

echo 正在啟用IIS功能

start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HttpRedirect;

echo 管理工具

start /w pkgmgr /iu:IIS-ManagementConsole;IIS-ManagementScriptingTools;IIS-ManagementService;IIS-IIS6ManagementCompatibility;IIS-Metabase;

rem IIS-WebServerManagementToolsIIS-WMICompatibility;IIS-LegacyScripts;IIS-LegacySnapIn;IIS-FTPPublishingService;IIS-FTPServer;IIS-FTPManagement;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI

 

echo 執行狀況和診斷

start /w pkgmgr /iu:IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;

rem start /w pkgmgr /iu:IIS-ODBCLogging;IIS-CustomLogging;IIS-RequestMonitor;IIS-HttpTracing;

 

echo 效能

start /w pkgmgr /iu:IIS-Performance;IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;

echo 安全性

start /w pkgmgr /iu:IIS-Security;IIS-BasicAuthentication;IIS-WindowsAuthentication

 

echo 應用程式

start /w pkgmgr /iu:IIS-ApplicationDevelopment;IIS-NetFxExtensibility;IIS-ServerSideIncludes;NetFx3;

start /w pkgmgr /iu:IIS-ASPNET;IIS-ISAPIExtensions;IIS-ISAPIFilter;

start /w pkgmgr /iu:NET-HTTP-Activation;NET-Non-HTTP-Activ;

start /w pkgmgr /iu:NET-WCF-Pipe-Activation;NET-WCF-HTTP-Activation;

start /w pkgmgr /iu:WCF-HTTP-Activation;WCF-NonHTTP-Activation;

rem start /w pkgmgr /iu:IIS-ASP;IIS-CGI;

 

 

rem ;IIS-DigestAuthentication;IIS-ClientCertificateMappingAuthentication;IIS-IISCertificateMappingAuthentication;IIS-URLAuthorization;IIS-RequestFiltering;IIS-IPSecurity;

 

goto :kuaijie

 

:win2008

echo 正在啟用Net Framework3.5

DISM /Online /Enable-Feature /FeatureName:NetFx3

 

echo 正在安裝IIS這可能需要幾分鐘...

dism /Online /Enable-Feature /FeatureName:IIS-WebServerRole /FeatureName:IIS-WebServer /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-HttpErrors /FeatureName:IIS-HttpRedirect /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-HttpLogging /FeatureName:IIS-LoggingLibraries /FeatureName:IIS-Security /FeatureName:IIS-RequestFiltering /FeatureName:IIS-Performance /FeatureName:IIS-HttpCompressionDynamic /FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-ManagementScriptingTools /FeatureName:IIS-IIS6ManagementCompatibility /FeatureName:IIS-Metabase /FeatureName:IIS-WindowsAuthentication /FeatureName:IIS-StaticContent /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-BasicAuthentication /FeatureName:IIS-ServerSideIncludes /FeatureName:IIS-HttpCompressionStatic /FeatureName:IIS-ManagementConsole /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-ISAPIExtensions /FeatureName:WAS-WindowsActivationService /FeatureName:WAS-ProcessModel /FeatureName:WAS-ConfigurationAPI /FeatureName:WAS-NetFxEnvironment

 

echo 正在啟用IIS功能

 

 

dism /Online /Enable-Feature /FeatureName:IIS-ASPNET /FeatureName:IIS-NetFxExtensibility /FeatureName:IIS-HostableWebCore /FeatureName:WCF-HTTP-Activation /FeatureName:WAS-NetFxEnvironment /FeatureName:WCF-NonHTTP-Activation /FeatureName:WCF-HTTP-Activation

goto :kuaijie

 

:win2012

echo 正在啟用Net Framework3.5

DISM /Online /Enable-Feature /FeatureName:NetFx3 /All

 

echo 正在安裝IIS這可能需要幾分鐘...

dism /Online /Enable-Feature /FeatureName:IIS-WebServerRole /FeatureName:IIS-WebServer /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-HttpErrors /FeatureName:IIS-HttpRedirect /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-HttpLogging /FeatureName:IIS-LoggingLibraries /FeatureName:IIS-Security /FeatureName:IIS-RequestFiltering /FeatureName:IIS-Performance /FeatureName:IIS-HttpCompressionDynamic /FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-ManagementScriptingTools /FeatureName:IIS-IIS6ManagementCompatibility /FeatureName:IIS-Metabase /FeatureName:IIS-WindowsAuthentication /FeatureName:IIS-StaticContent /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-BasicAuthentication /FeatureName:IIS-ServerSideIncludes /FeatureName:IIS-HttpCompressionStatic /FeatureName:IIS-ManagementConsole /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-ISAPIExtensions /FeatureName:WAS-WindowsActivationService /FeatureName:WAS-ProcessModel /FeatureName:WAS-ConfigurationAPI /FeatureName:WAS-NetFxEnvironment /FeatureName:NetFx4Extended-ASPNET45

 

echo 正在啟用IIS功能

 

 

dism /Online /Enable-Feature /FeatureName:IIS-ASPNET /FeatureName:IIS-NetFxExtensibility /FeatureName:IIS-HostableWebCore /FeatureName:WCF-HTTP-Activation /FeatureName:WAS-NetFxEnvironment /FeatureName:WCF-NonHTTP-Activation /FeatureName:WCF-HTTP-Activation /FeatureName:WCF-HTTP-Activation45 /FeatureName:IIS-ASPNET45 /FeatureName:WCF-Services45 /FeatureName:IIS-NetFxExtensibility45

 

 

goto :kuaijie

 

 

:kuaijie

start /w pkgmgr /iu:TelnetClient

echo 正在建立IIS桌面快捷方式

echo [InternetShortcut] >>"C:\Users\Administrator\Desktop\Internet 資訊服務(IIS)管理器.url"

echo URL="%SystemRoot%\system32\inetsrv\InetMgr.exe" >>"C:\Users\Administrator\Desktop\Internet 資訊服務(IIS)管理器.url"

echo IconIndex=0 >>"C:\Users\Administrator\Desktop\Internet 資訊服務(IIS)管理器.url"

echo IconFile="%SystemRoot%\system32\inetsrv\InetMgr.exe" >>"C:\Users\Administrator\Desktop\Internet 資訊服務(IIS)管理器.url"

echo IIS安裝完成

pause

exit

@@#

 

 

 

Windows 7

 

Windows 7 sp1

 

Windows 2008 R2

Windows 2008 r2 sp1

 

Windows 8.1

 

Windows 2012 r2

 

Windows 2016

 

Windows 2019

 

Windows 10

 

相關文章