国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

vbscript調用WMI一鍵式式發布網站

2019-11-17 01:44:05
字體:
來源:轉載
供稿:網友

vbscript調用WMI一鍵式式發布網站

作為.net開發,在window環境下,不得不熟悉些腳本語言,來減輕些日常開發中所遇到的一些繁雜的事情,比如自動發布網站,自動發布網站等等。

WMI windows管理程序接口,可用各種與語言調用,方便起見,我選擇VBscript腳本語言來實現一鍵式發布網站

所需WMI對象

Set oWebAdmin=GetObject("winmgmts:root/WebAdministration")

oWebAdmin 提供管理 siteapplicationVirtualDirectory 等對象的管理,調用對應對象的所提供的方法即可實現所需功能

獲取網站名稱,建立IIS后系統會自動創建一個默認網站,對應的ID為1

'---------------------------'-----獲取網站名稱----------'---------------------------Sub GetSiteName()  Set Sites=oWebAdmin.InstancesOf("Site")  For Each site In Sites     If site.Id=1 Then      strWebSiteName=site.Name      Exit For    End If  nextEnd Sub

建立虛擬目錄,需要三個參數 應用程序路徑,物理路徑,網站名稱

'---------------------------'-----創建虛擬目錄----------'---------------------------Sub CreateVD() Set vds=oWebAdmin.InstancesOf("VirtualDirectory") For Each vd In vds If vd.PhysicalPath=strPyhicPath Then    '刪除應用程序     DeleteApp strAppPath     vd.Delete_    Exit for End If Next Set vd=oWebAdmin.Get("VirtualDirectory") vd.Create strAppPath,"/",strPyhicPath,strWebSiteNameEnd Sub

創建應用程序 ,也需要三個參數 應用程序路徑,物理路徑,網站名稱

'---------------------------'-----創建應用程序----------'---------------------------Sub CreateApp(apppath,webSiteName,pypath) On Error Resume next App.Create apppath,webSiteName,pypath If Err.Number<>0 Then  WScript.Echo "創建應用程序錯誤:"&apppath&"錯誤碼:"&Err.Number  WScript.Sleep 500 else WScript.Echo "正在建立應用程序:"&apppath&"..." WScript.Sleep 1000 End ifEnd Sub

通過以上三個步驟即可自動創建一個虛擬目錄,并轉換為應用程序,根據IIS版本不同,調用WMI的對象也不同,所以以上代碼只正對IIS7

全部代碼如下

Dim WshShellSet WshShell = WScript.CreateObject("Wscript.Shell")If LCase(Right(WScript.FullName,11))="wscript.exe" Then WshShell.Run "cmd /k cscript.exe //nologo " & Chr(34)& WScript.ScriptFullName & Chr(34) WScript.QuitEnd ifstrWebSiteName=""strPyhicPath=InputBox("請輸入要發布網站的路徑"&vbnewline&vbnewline&"如:D:/xxxx/xxx"&vbNewLine&vbNewLine&"請確保是否存在網站:Default Web Site","提示")If(strPyhicPath="") Then MsgBox("請輸入路徑") WScript.QuitEnd ifary=Split(strPyhicPath,"/")strAppPath="/"&ary(UBound(ary))Set oWebAdmin=GetObject("winmgmts:root/WebAdministration") GetSiteNameCreateVDSet App=oWebAdmin.Get("Application")CreateApp strAppPath&"/Web", strWebSiteName,strPyhicPath&"/Web"CreateApp strAppPath&"/WebService", strWebSiteName,strPyhicPath&"/WebService"CreateIISAppByFile(strPyhicPath&"/WebService")WScript.Echo "處理完畢..."WScript.Sleep(1000)'---------------------------'-----獲取網站名稱----------'---------------------------Sub GetSiteName()  Set Sites=oWebAdmin.InstancesOf("Site")  For Each site In Sites     If site.Id=1 Then      strWebSiteName=site.Name      Exit For    End If  nextEnd Sub'---------------------------'-----創建虛擬目錄----------'---------------------------Sub CreateVD() Set vds=oWebAdmin.InstancesOf("VirtualDirectory") For Each vd In vds If vd.PhysicalPath=strPyhicPath Then    '刪除應用程序     DeleteApp strAppPath     vd.Delete_    Exit for End If Next Set vd=oWebAdmin.Get("VirtualDirectory") vd.Create strAppPath,"/",strPyhicPath,strWebSiteNameEnd Sub'---------------------------'-----循環創建Webservice----'---------------------------Sub CreateIISAppByFile(strFolder)    Set ofso = CreateObject("Scripting.FileSystemObject")    Set oFolder = oFSO.GetFolder(strFolder)    For Each x In oFolder.SubFolders       currAppPath=strAppPath&"/WebService/"&x.Name       CreateApp currAppPath,strWebSiteName,x.Path    NextEnd Sub'---------------------------'-----創建應用程序----------'---------------------------Sub CreateApp(apppath,webSiteName,pypath) On Error Resume next App.Create apppath,webSiteName,pypath If Err.Number<>0 Then  WScript.Echo "創建應用程序錯誤:"&apppath&"錯誤碼:"&Err.Number  WScript.Sleep 500 else WScript.Echo "正在建立應用程序:"&apppath&"..." WScript.Sleep 1000 End ifEnd Sub'---------------------------'-----刪除應用程序----------'---------------------------Sub DeleteApp(apppath)Set oApps = oWebAdmin.InstancesOf("Application")Set Re=New RegExpp=Replace(apppath,".","/.")re.Pattern=p&".*"re.IgnoreCase=falseFor Each oApp In oApps  If re.Test(oApp.Path) then   WScript.Echo("正在刪除應用程序:"& oApp.Path)   oApp.Delete_   WScript.Sleep(200)  End ifNextEnd sub


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 左权县| 仁布县| 五大连池市| 青岛市| 山丹县| 贺兰县| 郧西县| 广安市| 马关县| 宜兴市| 阜城县| 湟源县| 太和县| 水富县| 泰安市| 苏尼特右旗| 万山特区| 蓝田县| 盈江县| 广丰县| 会泽县| 钟山县| 恩施市| 宕昌县| 兴义市| 子长县| 堆龙德庆县| 宜川县| 布拖县| 修文县| 东光县| 化州市| 房产| 云霄县| 灵武市| 昌吉市| 呼伦贝尔市| 溧水县| 石家庄市| 龙泉市| 黄骅市|