經過研究,終於使用批處理解決了站點發布步驟多的問題。
完整批處理如下:
@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:指定網站文件目錄。
大概就這么點了。反正不復雜,還可以指定更多的站點配置。相關的配置就請大家自行查找了。