使用批处理自动发布IIS站点,基于IIS7及以上

经过研究,终于使用批处理解决了站点发布步骤多的问题。

完整批处理如下:

@set "sitePath=%~dp0"

@echo 新建程序池
@C:\Windows\System32\inetsrv\appcmd.exe add apppool /name:"新程序池" /managedRuntimeVersion:"v4.0"
@C:\Windows\System32\inetsrv\appcmd.exe stop site "Default Web Site"
@C:\Windows\System32\inetsrv\appcmd.exe add site /name:"新站点" /bindings:http/*:80: /applicationDefaults.applicationPool:"新程序池" /physicalPath:%sitePath%

Pause

  

将上面的批处理代码保存成bat文件,放在要发布的网站文件夹的根目录下,右键,以管理员身份运行即可。

详解:

set "sitePath=%~dp0" 得到批处理文件所在目录,由于批处理文件放在网站跟目录下,所以即是得到网站的完整目录路径。

C:\Windows\System32\inetsrv\appcmd.exe add apppool /name:"新程序池" /managedRuntimeVersion:"v4.0"

新建程序池,不多说。

C:\Windows\System32\inetsrv\appcmd.exe stop site "Default Web Site"

停止默认站点,主要是我做的时候,要求默认站点停止掉,以让出80端口。可以根据自己需要是否要停止默认站点。

C:\Windows\System32\inetsrv\appcmd.exe add site /name:"新站点" /bindings:http/*:80: /applicationDefaults.applicationPool:"新程序池" /physicalPath:%sitePath%

新建站点,指定名称,

/bindings:访问地址及端口绑定。指定程序池。

/applicationDefaults.applicationPool:指定程序池

/physicalPath:指定网站文件目录。

大概就这么点了。反正不复杂,还可以指定更多的站点配置。相关的配置就请大家自行查找了。