使用vbs脚本检查网站是否使用asp.net
生活随笔
收集整理的這篇文章主要介紹了
使用vbs脚本检查网站是否使用asp.net
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Const AspNetExt="aspx" Dim Obj,Fso,F,Val,i
Set Obj=New IISClass
Set Fso=CreateObject("Scripting.FileSystemObject")
Set F = Fso.CreateTextFile("是否有Net程序.txt", True) Obj.GetIIS
i=0
For Each Val In Obj.Site
?i=i+1
?WScript.Echo Fill(i,4) & "正在檢測站點 " & Val.Name & " 是否有" & AspNetExt & "文件:"
?Path=Val.Path
?If CheckAspNet(Path) Then
??WScript.Echo vbTab & "有"
??F.WriteLine Fill(Val.Name,25) & Path
?Else
??WScript.Echo vbTab & "沒有"
?End If
Next F.Close()
Set Fso=Nothing
Set Obj=Nothing Function CheckAspNet(ByRef Path)
?Dim F,Folder,Files,fName,ExtName,dPath
?Dim Fso
?Set Fso=CreateObject("Scripting.FileSystemObject")
?Set F=Fso.GetFolder(Path)
?CheckAspNet=False For Each Files In F.Files
??fName=Files.Name
??ExtName=Fso.GetExtensionName(Path & "\" & fName)
??If LCase(ExtName)=LCase(AspNetExt) Then
???CheckAspNet=True
???Exit Function
??End If
?Next For Each Folder In F.SubFolders
??dPath=Path & "\" & Folder.Name
??If CheckAspNet(dPath) Then
???CheckAspNet=True
???Exit Function
??End If
?Next
?Set F=Nothing
?Set Fso=Nothing
End Function
Function Fill(byRef Str,byRef L)
?Dim Tmp
?If CLng(L)<=Len(Str) Then
??Fill=Str
??Exit Function
?End If
?Tmp=Str & Space(L)
?Fill=Left(Tmp,L)
End Function
'IIS操作類,包含創建應用程序池、站點和用戶的功能
Class IISClass
?Public Site()
?Public AppPool()
?Private SiteN,PoolN
?Private AnonyMouseName,ComputerName
?Private AppPoolAndIIsSplitStr,SplitStr
?Private CreateSiteTmpNum Private Sub Class_Initialize()
??SiteN=0
??PoolN=0
??ComputerName=GetComputerName
??AnonyMouseName="IUSR_" & ComputerName
??AppPoolAndIIsSplitStr=vbCrlf & "|AppPoolEndIIsStart|" & vbCrLf??'生成備份文件時,應用程序池和IIS站點信息的分隔線
??SplitStr="<|>"
??CreateSiteTmpNum=0
?End Sub
?
?'獲取當前計算機的名稱
?Private Function GetComputerName()
??Dim ObjNetWork,NetworkStr
??NetworkStr="Wscript.Network"
??Set objNetwork = CreateObject(NetworkStr)
??GetComputerName = objNetwork.ComputerName
??Set ObjNetWork=Nothing
?End Function
?
?'把域名綁定的對象轉換成數組的原始數據
?Private Function DomainObjToArr(ByRef Obj)
??Dim Tmp(),Val,i,s
??i=0
??s=""
??For Each Val In Obj
???ReDim Preserve Tmp(i)
???s=Val.IP & ":" & Val.Port & ":" & Val.Domain
???Tmp(i)=s
???i=i+1
??Next
??DomainObjToArr=Tmp
?End Function '把用戶添加到指定的組中
?Public Function AddUserToGroup(byRef UserName,byRef GroupName,ByRef ErrMsg)
??Dim Obj,GroupObj
??AddUserToGroup=False
??On Error Resume Next
??Err.Clear
??Set Obj=GetObject("WinNT://" & ComputerName)
??If Err.number<>0 Then
???ErrMsg="無法使用ADSI功能"
???Exit Function
??End If
??Err.Clear
??Set GroupObj=Obj.GetObject("Group",GroupName)
??If Err.number<>0 Then
???ErrMsg="控制用戶組失敗,請檢查組的名稱是否正確"
???Exit Function
??End If
??Err.Clear
??GroupObj.add("WinNT://" & ComputerName & "/" & UserName)
??If Err.number<>0 Then
???ErrMsg="在把用戶添加到組中時出現錯誤,可能是該組中已存在此用戶"
???Exit Function
??End If
??AddUserToGroup=True
??Set Obj=Nothing
??Set GroupObj=Nothing
?End Function '創建一個用戶
?Function CreateUser(byRef UserName,byRef UserPass,byRef FullName,byRef ExtInfo,ByRef ErrMsg)
??Dim ComputerObj,NewUser
??CreateUser=False
??On Error Resume Next
??Err.Clear
??Set ComputerObj = GetObject("WinNT://"& ComputerName)
??If Err.number<>0 Then
???ErrMsg="無法使用ADSI功能"
???Exit Function
??End If
??Err.Clear????
??Set NewUser = ComputerObj.Create("User" , UserName)??
??NewUser.SetInfo
??If Err.number<>0 Then
???ErrMsg="創建用戶出錯" & Err.Description
???Exit Function
??End If
??Err.Clear
??'進行帳號設置
??NewUser.SetPassword UserPass?'帳號密碼
??NewUser.FullName=FullName??'帳號全名
??NewUser.Description=ExtInfo??'帳號說明
??NewUser.UserFlags=&H10040??'&H20000(使用者下次登入時須變更密碼) &H0040(使用者不得變更密碼) &H10000(密碼永久正確) &H0002(帳戶暫時停用)
??NewUser.SetInfo
??If Err.number<>0 Then
???ErrMsg="設置用戶信息時出錯" & Err.Description
???Exit Function
??End If
??Set ComputerObj=nothing
??CreateUser=True
?End Function
? '創建一個應用程序池
?Public Function CreateAppPool(ByRef AppPoolObj,ByRef ErrMsg)
??Dim ServerObj, AppObj
??CreateAppPool=False
??On Error Resume Next
??Set ServerObj = GetObject("IIS://Localhost/W3SVC/AppPools")
??Err.Clear
??Set AppObj = ServerObj.Create("IIsApplicationPool", AppPoolObj.Name)
??AppObj.SetInfo
??If Err.Number <> 0 Then
???ErrMsg="創建應用程序池出錯" & Err.Description
???Exit Function
??End If
??Set AppObj=Nothing
??Set ServerObj=Nothing
??CreateAppPool=True
?End Function '設置站點的應用程序池
?Public Function SetSiteAppPool(ByRef SiteObj,ByRef ErrMsg)
??Dim WWWServer,Obj
??SetSiteAppPool=False
??On Error Resume Next
??Err.Clear
??Set WWWServer = GetObject(SiteObj.AdsPath & "/ROOT")
??WWWServer.AppPoolId=SiteObj.AppPool
??WWWServer.SetInfo
??If Err.Number<>0 Then
???ErrMsg="設置站點的應用程序池時出錯"
???Exit Function
??End If
??Set WWWServer=Nothing
??SetSiteAppPool=True
?End Function
?
?'設置站點的用戶名和密碼
?Public Function SetSiteUser(ByRef SiteObj,ByRef ErrMsg)
??Dim WWWServer,Obj
??SetSiteUser=False
??If SiteObj.User<>"" And SiteObj.Password<>"" Then
???On Error Resume Next
???Err.Clear
???Set WWWServer = GetObject(SiteObj.AdsPath & "/ROOT")
???WWWServer.AnonymousUserName=SiteObj.User
???WWWServer.AnonymousUserPass=SiteObj.Password
???WWWServer.SetInfo
???If Err.Number<>0 Then
????ErrMsg="設置站點的用戶名和密碼時出錯"
????Exit Function
???End If
???Set WWWServer=Nothing
??Else
???ErrMsg="沒有設置用戶名和密碼"
???Exit Function
??End If
??SetSiteUser=True
?End Function
?'創建一個站點,由于便與分析出錯信息,此處創建站點只創建最基本的屬性(站點名稱,綁定域名,站點目錄)
?Public Function CreateSite(ByRef SiteObj,ByRef ErrMsg)
??'默認從配置文件中獲取的信息不會出錯,不再寫容錯處理程序
??Dim WWWServer,IIsAdsNum,TmpObj,VDirObj,ServerObj
??CreateSite=False
??On Error Resume Next
??Set WWWServer = GetObject("IIS://Localhost/W3SVC")
??IIsAdsNum=SiteObj.AdsNum
??Err.Clear
??Set TmpObj = WWWServer.GetObject("IIsWebServer", IIsAdsNum)
??If Err.Number = 0 Then
???Err.Clear
???'程序執行沒有出錯說明該站點已存在
???ErrMsg = "該服務器已經存在和此站點AdsPath相同的站點"
???Exit Function
??End If
??'開始創建站點
??Err.Clear
??????? Set ServerObj = WWWServer.Create("IIsWebServer", IIsAdsNum)
??If Err.Number <> 0 Then
???ErrMsg = "創建站點失敗"
???Exit Function
??End If
??'配置站點
??Err.Clear
??ServerObj.ServerComment = SiteObj.Name
??ServerObj.LogType=SiteObj.LogType
??If SiteObj.LogType Then
???ServerObj.LogFileDirectory=SiteObj.LogDir
??End If
??ServerObj.ServerBindings = DomainObjToArr(SiteObj.Domains)
??ServerObj.SetInfo
??If Err.Number <> 0 Then
???ErrMsg = "配置站點時出錯"
???Exit Function
??End If
??'建立ROOT虛擬目錄
??Err.Clear
??Set VDirObj = ServerObj.Create("IIsWebVirtualDir", "ROOT")
??If Err.Number <> 0 Then
???ErrMsg = "創建ROOT虛擬目錄失敗"
???Exit Function
??End If '默認ROOT信息
??Err.Clear
??VDirObj.Path=SiteObj.Path
??VDirObj.DefaultDoc=SiteObj.DefaultDoc
??VDirObj.SetInfo
??If Err.Number <> 0 Then
???ErrMsg = "配置站點時出錯"
???Exit Function
??End If Err.Clear
??VDirObj.AppFriendlyName = "默認應用程序"
??VDirObj.SetInfo
??VDirObj.AppCreate2 2
??VDirObj.SetInfo
??VDirObj.AccessScript = True
??VDirObj.AccessFlags = 513
??VDirObj.SetInfo
??If Err.Number <> 0 Then
???ErrMsg = "配置ROOT虛擬目錄時出錯"
???Exit Function
??End If
??If CInt(SiteObj.Stat)=2 Then
???ServerObj.Start
??Else
???ServerObj.Stop
??End If
??
??Set VDirObj = Nothing
??Set TmpObj = Nothing
??Set ServerObj = Nothing
??Set WWWServer = Nothing
??CreateSite = True
?End Function '創建一個FTP
?Public Function CreateFTP(ByRef SiteObj,ByRef ErrMsg)
??Dim FtpObj,RootObj,VirObj
??On Error Resume Next
??CreateFTP=False
??If SiteObj.User<>"" And SiteObj.Password<>"" Then
???Err.Clear
???Set FtpObj= GetObject("IIS://Localhost/MSFTPSVC/1")
???Set RootObj=FtpObj.GetObject("IIsFtpVirtualDir", "ROOT")
???Set VirObj=RootObj.Create("IIsFtpVirtualDir",SiteObj.User)
???VirObj.AccessFlags=3
???VirObj.DontLog=0
???VirObj.Path=SiteObj.Path
???VirObj.SetInfo
???If Err.Number<>0 Then
????ErrMsg="創建站點失敗" & Err.Description
????Exit Function
???End If
???Set VirObj=Nothing
???Set RootObj=Nothing
???Set FtpObj=Nothing
??End If
??CreateFTP=True
?End Function '把IIS信息整合成文本內容
?Public Function BackUP()
??Dim Str,s,v
??Str=""
??s=""
??For Each v In AppPool
???If s="" Then
????s=v.Name
???Else
????s=s & "," & v.Name
???End If
??Next
??Str=s & AppPoolAndIIsSplitStr
??'以上為應用程序池的保存
??'下面保存IIS的信息
??s=""
??Dim Tmp,D,DStr
??Tmp=""
??For Each v In Site
???If CLng(v.AdsNum)<>1 Then
????DStr=""
????For Each D In v.Domains
?????If DStr="" Then
??????DStr=D.IP & ":" & D.Port & ":" & D.Domain
?????Else
??????DStr=DStr & "," & D.IP & ":" & D.Port & ":" & D.Domain
?????End If
????Next
????Tmp=v.Name & SplitStr & _
?????v.Path & SplitStr & _
?????v.User & SplitStr & _
?????v.Password & SplitStr & _
?????v.AppPool & SplitStr & _
?????v.DefaultDoc & SplitStr & _
?????v.LogType & SplitStr & _
?????v.LogDir & SplitStr & _
?????v.AdsPath & SplitStr & _
?????v.AdsNum & SplitStr & _
?????v.Stat & SplitStr & _
?????DStr If s="" Then
?????s=Tmp
????Else
?????s=s & vbCrLf & Tmp
????End If
???End If
??Next
??Str=Str & s
??Backup=Str
?End Function
?
?'從以前備份的IIS內容中讀出信息
?Public Sub ReadFromFile(ByRef Content)
??Dim Arr,PoolStr,IIsStr,Pool,S,TmpArr,Val
??Arr=Split(Content,AppPoolAndIIsSplitStr)
??PoolStr=Arr(0)
??IIsStr=Arr(1)
??For Each Pool In Split(PoolStr,",")
???ReDim Preserve AppPool(PoolN)
???Set AppPool(PoolN)=New AppPoolTypes
???AppPool(PoolN).Name=Pool
???PoolN=PoolN+1
??Next
??For Each S In Split(IIsStr,vbCrLf)
???ReDim Preserve Site(SiteN)
???Set Site(SiteN)=New IIsTypes
???TmpArr=Split(S,SplitStr) With Site(SiteN)
????.Name=TmpArr(0)
????.Path=TmpArr(1)
????.User=TmpArr(2)
????.Password=TmpArr(3)
????.AppPool=TmpArr(4)
????.DefaultDoc=TmpArr(5)
????.LogType=TmpArr(6)
????.LogDir=TmpArr(7)
????.AdsPath=TmpArr(8)
????.AdsNum=TmpArr(9)
????.Stat=TmpArr(10)
????For Each Val In Split(TmpArr(11),",")
?????.AddDomain Val
????Next
???End With
???SiteN=SiteN+1
??Next
?End Sub
?
?'從當前服務器上IIS中讀取應用程序池的列表
?Public Sub GetPool()
??Dim WWWObj,AppObj
??Set WWWObj=GetObject("IIS://Localhost/W3SVC/AppPools")
??For Each AppObj In WWWObj
???ReDim Preserve AppPool(PoolN)
???Set AppPool(PoolN)=New AppPoolTypes
???AppPool(PoolN).Name=AppObj.name
???PoolN=PoolN+1
??Next
??Set WWWObj=Nothing
?End Sub
?
?'從當前服務器上IIS中讀取站點的列表
?Public Sub GetIIS()
??Dim WWWObj,SiteObj,Obj,UserName,UserPass,SiteName
??Dim Binds,AppPool,VirObj
??'從IIS站點中獲取所有IIS信息
??Set WWWObj=GetObject("IIS://Localhost/w3svc")
??For Each SiteObj In WWWObj
???If SiteObj.Class="IIsWebServer" Then
????Binds=SiteObj.ServerBindings
????SiteName=SiteObj.ServerComment Set Obj=SiteObj.GetObject("IIsWebVirtualDir","ROOT")
????UserName=Obj.AnonymousUserName
????UserPass=Obj.AnonymousUserPass
????AppPool=Obj.AppPoolId
????'處理一下用戶名的信息
????UserName=Replace(UserName,ComputerName & "\","")
????UserName=Replace(UserName,AnonyMouseName,"")
????If UserName="" Then
?????UserName=""
?????UserPass=""
????End If
????ReDim Preserve Site(SiteN)
????Set Site(SiteN)=New IIsTypes
????With Site(SiteN)
?????.Name=SiteName
?????.Path=Obj.Path
?????.DefaultDoc=Obj.DefaultDoc
?????.LogType=SiteObj.LogType
?????.LogDir=SiteObj.LogFileDirectory
?????For Each Val In Binds
??????.AddDomain Val
?????Next
?????.User=UserName
?????.Password=UserPass
?????.AppPool=AppPool
?????.AdsPath=SiteObj.AdsPath
?????.AdsNum=SiteObj.Name
?????.Stat=SiteObj.Status
????End With
????SiteN=SiteN+1
???End If
??Next
??Set WWWObj=Nothing
?End Sub End Class '站點綁定信息數據類型
Class BindsTypes
?Public IP
?Public Domain
?Public Port
?Private Sub Class_Initialize()
??IP=""
??Domain=""
??Port="80"
?End Sub
End Class '應用程序池的數據類型
Class AppPoolTypes
?Public Name
?'由于池比較少,不再加大程序的復雜性,只記錄一下池的名稱就成了,其它信息由默認池中獲取
?Private Sub Class_Initialze()
??Name=""
?End Sub
End Class '站點的數據類型
Class IIsTypes
?Public Name
?Public Path
?Public Domains()
?Public User
?Public Password
?Public AppPool
?Public DefaultDoc
?Public LogDir,LogType
?Public AdsPath,AdsNum
?Public Stat Private DomainN
?Private Sub Class_Initialze()
??Name=""
??Path=""
??User=""
??Password=""
??AppPool=""
??DomainN=0
??AdsPath=""
??AdsNum=0
??Stat=2
?End Sub
?Public Sub AddDomain(ByRef Str)
??Dim Arr
??Arr=Split(Str,":")
??ReDim Preserve Domains(DomainN)
??Set Domains(DomainN)=New BindsTypes
??With Domains(DomainN)
???.IP=Arr(0)
???.Port=Arr(1)
???.Domain=Arr(2)
??End With
??DomainN=DomainN+1
?End Sub
End Class
?本文轉自 simeon2005 51CTO博客,原文鏈接:http://blog.51cto.com/simeon/99759
Set Obj=New IISClass
Set Fso=CreateObject("Scripting.FileSystemObject")
Set F = Fso.CreateTextFile("是否有Net程序.txt", True) Obj.GetIIS
i=0
For Each Val In Obj.Site
?i=i+1
?WScript.Echo Fill(i,4) & "正在檢測站點 " & Val.Name & " 是否有" & AspNetExt & "文件:"
?Path=Val.Path
?If CheckAspNet(Path) Then
??WScript.Echo vbTab & "有"
??F.WriteLine Fill(Val.Name,25) & Path
?Else
??WScript.Echo vbTab & "沒有"
?End If
Next F.Close()
Set Fso=Nothing
Set Obj=Nothing Function CheckAspNet(ByRef Path)
?Dim F,Folder,Files,fName,ExtName,dPath
?Dim Fso
?Set Fso=CreateObject("Scripting.FileSystemObject")
?Set F=Fso.GetFolder(Path)
?CheckAspNet=False For Each Files In F.Files
??fName=Files.Name
??ExtName=Fso.GetExtensionName(Path & "\" & fName)
??If LCase(ExtName)=LCase(AspNetExt) Then
???CheckAspNet=True
???Exit Function
??End If
?Next For Each Folder In F.SubFolders
??dPath=Path & "\" & Folder.Name
??If CheckAspNet(dPath) Then
???CheckAspNet=True
???Exit Function
??End If
?Next
?Set F=Nothing
?Set Fso=Nothing
End Function
Function Fill(byRef Str,byRef L)
?Dim Tmp
?If CLng(L)<=Len(Str) Then
??Fill=Str
??Exit Function
?End If
?Tmp=Str & Space(L)
?Fill=Left(Tmp,L)
End Function
'IIS操作類,包含創建應用程序池、站點和用戶的功能
Class IISClass
?Public Site()
?Public AppPool()
?Private SiteN,PoolN
?Private AnonyMouseName,ComputerName
?Private AppPoolAndIIsSplitStr,SplitStr
?Private CreateSiteTmpNum Private Sub Class_Initialize()
??SiteN=0
??PoolN=0
??ComputerName=GetComputerName
??AnonyMouseName="IUSR_" & ComputerName
??AppPoolAndIIsSplitStr=vbCrlf & "|AppPoolEndIIsStart|" & vbCrLf??'生成備份文件時,應用程序池和IIS站點信息的分隔線
??SplitStr="<|>"
??CreateSiteTmpNum=0
?End Sub
?
?'獲取當前計算機的名稱
?Private Function GetComputerName()
??Dim ObjNetWork,NetworkStr
??NetworkStr="Wscript.Network"
??Set objNetwork = CreateObject(NetworkStr)
??GetComputerName = objNetwork.ComputerName
??Set ObjNetWork=Nothing
?End Function
?
?'把域名綁定的對象轉換成數組的原始數據
?Private Function DomainObjToArr(ByRef Obj)
??Dim Tmp(),Val,i,s
??i=0
??s=""
??For Each Val In Obj
???ReDim Preserve Tmp(i)
???s=Val.IP & ":" & Val.Port & ":" & Val.Domain
???Tmp(i)=s
???i=i+1
??Next
??DomainObjToArr=Tmp
?End Function '把用戶添加到指定的組中
?Public Function AddUserToGroup(byRef UserName,byRef GroupName,ByRef ErrMsg)
??Dim Obj,GroupObj
??AddUserToGroup=False
??On Error Resume Next
??Err.Clear
??Set Obj=GetObject("WinNT://" & ComputerName)
??If Err.number<>0 Then
???ErrMsg="無法使用ADSI功能"
???Exit Function
??End If
??Err.Clear
??Set GroupObj=Obj.GetObject("Group",GroupName)
??If Err.number<>0 Then
???ErrMsg="控制用戶組失敗,請檢查組的名稱是否正確"
???Exit Function
??End If
??Err.Clear
??GroupObj.add("WinNT://" & ComputerName & "/" & UserName)
??If Err.number<>0 Then
???ErrMsg="在把用戶添加到組中時出現錯誤,可能是該組中已存在此用戶"
???Exit Function
??End If
??AddUserToGroup=True
??Set Obj=Nothing
??Set GroupObj=Nothing
?End Function '創建一個用戶
?Function CreateUser(byRef UserName,byRef UserPass,byRef FullName,byRef ExtInfo,ByRef ErrMsg)
??Dim ComputerObj,NewUser
??CreateUser=False
??On Error Resume Next
??Err.Clear
??Set ComputerObj = GetObject("WinNT://"& ComputerName)
??If Err.number<>0 Then
???ErrMsg="無法使用ADSI功能"
???Exit Function
??End If
??Err.Clear????
??Set NewUser = ComputerObj.Create("User" , UserName)??
??NewUser.SetInfo
??If Err.number<>0 Then
???ErrMsg="創建用戶出錯" & Err.Description
???Exit Function
??End If
??Err.Clear
??'進行帳號設置
??NewUser.SetPassword UserPass?'帳號密碼
??NewUser.FullName=FullName??'帳號全名
??NewUser.Description=ExtInfo??'帳號說明
??NewUser.UserFlags=&H10040??'&H20000(使用者下次登入時須變更密碼) &H0040(使用者不得變更密碼) &H10000(密碼永久正確) &H0002(帳戶暫時停用)
??NewUser.SetInfo
??If Err.number<>0 Then
???ErrMsg="設置用戶信息時出錯" & Err.Description
???Exit Function
??End If
??Set ComputerObj=nothing
??CreateUser=True
?End Function
? '創建一個應用程序池
?Public Function CreateAppPool(ByRef AppPoolObj,ByRef ErrMsg)
??Dim ServerObj, AppObj
??CreateAppPool=False
??On Error Resume Next
??Set ServerObj = GetObject("IIS://Localhost/W3SVC/AppPools")
??Err.Clear
??Set AppObj = ServerObj.Create("IIsApplicationPool", AppPoolObj.Name)
??AppObj.SetInfo
??If Err.Number <> 0 Then
???ErrMsg="創建應用程序池出錯" & Err.Description
???Exit Function
??End If
??Set AppObj=Nothing
??Set ServerObj=Nothing
??CreateAppPool=True
?End Function '設置站點的應用程序池
?Public Function SetSiteAppPool(ByRef SiteObj,ByRef ErrMsg)
??Dim WWWServer,Obj
??SetSiteAppPool=False
??On Error Resume Next
??Err.Clear
??Set WWWServer = GetObject(SiteObj.AdsPath & "/ROOT")
??WWWServer.AppPoolId=SiteObj.AppPool
??WWWServer.SetInfo
??If Err.Number<>0 Then
???ErrMsg="設置站點的應用程序池時出錯"
???Exit Function
??End If
??Set WWWServer=Nothing
??SetSiteAppPool=True
?End Function
?
?'設置站點的用戶名和密碼
?Public Function SetSiteUser(ByRef SiteObj,ByRef ErrMsg)
??Dim WWWServer,Obj
??SetSiteUser=False
??If SiteObj.User<>"" And SiteObj.Password<>"" Then
???On Error Resume Next
???Err.Clear
???Set WWWServer = GetObject(SiteObj.AdsPath & "/ROOT")
???WWWServer.AnonymousUserName=SiteObj.User
???WWWServer.AnonymousUserPass=SiteObj.Password
???WWWServer.SetInfo
???If Err.Number<>0 Then
????ErrMsg="設置站點的用戶名和密碼時出錯"
????Exit Function
???End If
???Set WWWServer=Nothing
??Else
???ErrMsg="沒有設置用戶名和密碼"
???Exit Function
??End If
??SetSiteUser=True
?End Function
?'創建一個站點,由于便與分析出錯信息,此處創建站點只創建最基本的屬性(站點名稱,綁定域名,站點目錄)
?Public Function CreateSite(ByRef SiteObj,ByRef ErrMsg)
??'默認從配置文件中獲取的信息不會出錯,不再寫容錯處理程序
??Dim WWWServer,IIsAdsNum,TmpObj,VDirObj,ServerObj
??CreateSite=False
??On Error Resume Next
??Set WWWServer = GetObject("IIS://Localhost/W3SVC")
??IIsAdsNum=SiteObj.AdsNum
??Err.Clear
??Set TmpObj = WWWServer.GetObject("IIsWebServer", IIsAdsNum)
??If Err.Number = 0 Then
???Err.Clear
???'程序執行沒有出錯說明該站點已存在
???ErrMsg = "該服務器已經存在和此站點AdsPath相同的站點"
???Exit Function
??End If
??'開始創建站點
??Err.Clear
??????? Set ServerObj = WWWServer.Create("IIsWebServer", IIsAdsNum)
??If Err.Number <> 0 Then
???ErrMsg = "創建站點失敗"
???Exit Function
??End If
??'配置站點
??Err.Clear
??ServerObj.ServerComment = SiteObj.Name
??ServerObj.LogType=SiteObj.LogType
??If SiteObj.LogType Then
???ServerObj.LogFileDirectory=SiteObj.LogDir
??End If
??ServerObj.ServerBindings = DomainObjToArr(SiteObj.Domains)
??ServerObj.SetInfo
??If Err.Number <> 0 Then
???ErrMsg = "配置站點時出錯"
???Exit Function
??End If
??'建立ROOT虛擬目錄
??Err.Clear
??Set VDirObj = ServerObj.Create("IIsWebVirtualDir", "ROOT")
??If Err.Number <> 0 Then
???ErrMsg = "創建ROOT虛擬目錄失敗"
???Exit Function
??End If '默認ROOT信息
??Err.Clear
??VDirObj.Path=SiteObj.Path
??VDirObj.DefaultDoc=SiteObj.DefaultDoc
??VDirObj.SetInfo
??If Err.Number <> 0 Then
???ErrMsg = "配置站點時出錯"
???Exit Function
??End If Err.Clear
??VDirObj.AppFriendlyName = "默認應用程序"
??VDirObj.SetInfo
??VDirObj.AppCreate2 2
??VDirObj.SetInfo
??VDirObj.AccessScript = True
??VDirObj.AccessFlags = 513
??VDirObj.SetInfo
??If Err.Number <> 0 Then
???ErrMsg = "配置ROOT虛擬目錄時出錯"
???Exit Function
??End If
??If CInt(SiteObj.Stat)=2 Then
???ServerObj.Start
??Else
???ServerObj.Stop
??End If
??
??Set VDirObj = Nothing
??Set TmpObj = Nothing
??Set ServerObj = Nothing
??Set WWWServer = Nothing
??CreateSite = True
?End Function '創建一個FTP
?Public Function CreateFTP(ByRef SiteObj,ByRef ErrMsg)
??Dim FtpObj,RootObj,VirObj
??On Error Resume Next
??CreateFTP=False
??If SiteObj.User<>"" And SiteObj.Password<>"" Then
???Err.Clear
???Set FtpObj= GetObject("IIS://Localhost/MSFTPSVC/1")
???Set RootObj=FtpObj.GetObject("IIsFtpVirtualDir", "ROOT")
???Set VirObj=RootObj.Create("IIsFtpVirtualDir",SiteObj.User)
???VirObj.AccessFlags=3
???VirObj.DontLog=0
???VirObj.Path=SiteObj.Path
???VirObj.SetInfo
???If Err.Number<>0 Then
????ErrMsg="創建站點失敗" & Err.Description
????Exit Function
???End If
???Set VirObj=Nothing
???Set RootObj=Nothing
???Set FtpObj=Nothing
??End If
??CreateFTP=True
?End Function '把IIS信息整合成文本內容
?Public Function BackUP()
??Dim Str,s,v
??Str=""
??s=""
??For Each v In AppPool
???If s="" Then
????s=v.Name
???Else
????s=s & "," & v.Name
???End If
??Next
??Str=s & AppPoolAndIIsSplitStr
??'以上為應用程序池的保存
??'下面保存IIS的信息
??s=""
??Dim Tmp,D,DStr
??Tmp=""
??For Each v In Site
???If CLng(v.AdsNum)<>1 Then
????DStr=""
????For Each D In v.Domains
?????If DStr="" Then
??????DStr=D.IP & ":" & D.Port & ":" & D.Domain
?????Else
??????DStr=DStr & "," & D.IP & ":" & D.Port & ":" & D.Domain
?????End If
????Next
????Tmp=v.Name & SplitStr & _
?????v.Path & SplitStr & _
?????v.User & SplitStr & _
?????v.Password & SplitStr & _
?????v.AppPool & SplitStr & _
?????v.DefaultDoc & SplitStr & _
?????v.LogType & SplitStr & _
?????v.LogDir & SplitStr & _
?????v.AdsPath & SplitStr & _
?????v.AdsNum & SplitStr & _
?????v.Stat & SplitStr & _
?????DStr If s="" Then
?????s=Tmp
????Else
?????s=s & vbCrLf & Tmp
????End If
???End If
??Next
??Str=Str & s
??Backup=Str
?End Function
?
?'從以前備份的IIS內容中讀出信息
?Public Sub ReadFromFile(ByRef Content)
??Dim Arr,PoolStr,IIsStr,Pool,S,TmpArr,Val
??Arr=Split(Content,AppPoolAndIIsSplitStr)
??PoolStr=Arr(0)
??IIsStr=Arr(1)
??For Each Pool In Split(PoolStr,",")
???ReDim Preserve AppPool(PoolN)
???Set AppPool(PoolN)=New AppPoolTypes
???AppPool(PoolN).Name=Pool
???PoolN=PoolN+1
??Next
??For Each S In Split(IIsStr,vbCrLf)
???ReDim Preserve Site(SiteN)
???Set Site(SiteN)=New IIsTypes
???TmpArr=Split(S,SplitStr) With Site(SiteN)
????.Name=TmpArr(0)
????.Path=TmpArr(1)
????.User=TmpArr(2)
????.Password=TmpArr(3)
????.AppPool=TmpArr(4)
????.DefaultDoc=TmpArr(5)
????.LogType=TmpArr(6)
????.LogDir=TmpArr(7)
????.AdsPath=TmpArr(8)
????.AdsNum=TmpArr(9)
????.Stat=TmpArr(10)
????For Each Val In Split(TmpArr(11),",")
?????.AddDomain Val
????Next
???End With
???SiteN=SiteN+1
??Next
?End Sub
?
?'從當前服務器上IIS中讀取應用程序池的列表
?Public Sub GetPool()
??Dim WWWObj,AppObj
??Set WWWObj=GetObject("IIS://Localhost/W3SVC/AppPools")
??For Each AppObj In WWWObj
???ReDim Preserve AppPool(PoolN)
???Set AppPool(PoolN)=New AppPoolTypes
???AppPool(PoolN).Name=AppObj.name
???PoolN=PoolN+1
??Next
??Set WWWObj=Nothing
?End Sub
?
?'從當前服務器上IIS中讀取站點的列表
?Public Sub GetIIS()
??Dim WWWObj,SiteObj,Obj,UserName,UserPass,SiteName
??Dim Binds,AppPool,VirObj
??'從IIS站點中獲取所有IIS信息
??Set WWWObj=GetObject("IIS://Localhost/w3svc")
??For Each SiteObj In WWWObj
???If SiteObj.Class="IIsWebServer" Then
????Binds=SiteObj.ServerBindings
????SiteName=SiteObj.ServerComment Set Obj=SiteObj.GetObject("IIsWebVirtualDir","ROOT")
????UserName=Obj.AnonymousUserName
????UserPass=Obj.AnonymousUserPass
????AppPool=Obj.AppPoolId
????'處理一下用戶名的信息
????UserName=Replace(UserName,ComputerName & "\","")
????UserName=Replace(UserName,AnonyMouseName,"")
????If UserName="" Then
?????UserName=""
?????UserPass=""
????End If
????ReDim Preserve Site(SiteN)
????Set Site(SiteN)=New IIsTypes
????With Site(SiteN)
?????.Name=SiteName
?????.Path=Obj.Path
?????.DefaultDoc=Obj.DefaultDoc
?????.LogType=SiteObj.LogType
?????.LogDir=SiteObj.LogFileDirectory
?????For Each Val In Binds
??????.AddDomain Val
?????Next
?????.User=UserName
?????.Password=UserPass
?????.AppPool=AppPool
?????.AdsPath=SiteObj.AdsPath
?????.AdsNum=SiteObj.Name
?????.Stat=SiteObj.Status
????End With
????SiteN=SiteN+1
???End If
??Next
??Set WWWObj=Nothing
?End Sub End Class '站點綁定信息數據類型
Class BindsTypes
?Public IP
?Public Domain
?Public Port
?Private Sub Class_Initialize()
??IP=""
??Domain=""
??Port="80"
?End Sub
End Class '應用程序池的數據類型
Class AppPoolTypes
?Public Name
?'由于池比較少,不再加大程序的復雜性,只記錄一下池的名稱就成了,其它信息由默認池中獲取
?Private Sub Class_Initialze()
??Name=""
?End Sub
End Class '站點的數據類型
Class IIsTypes
?Public Name
?Public Path
?Public Domains()
?Public User
?Public Password
?Public AppPool
?Public DefaultDoc
?Public LogDir,LogType
?Public AdsPath,AdsNum
?Public Stat Private DomainN
?Private Sub Class_Initialze()
??Name=""
??Path=""
??User=""
??Password=""
??AppPool=""
??DomainN=0
??AdsPath=""
??AdsNum=0
??Stat=2
?End Sub
?Public Sub AddDomain(ByRef Str)
??Dim Arr
??Arr=Split(Str,":")
??ReDim Preserve Domains(DomainN)
??Set Domains(DomainN)=New BindsTypes
??With Domains(DomainN)
???.IP=Arr(0)
???.Port=Arr(1)
???.Domain=Arr(2)
??End With
??DomainN=DomainN+1
?End Sub
End Class
?本文轉自 simeon2005 51CTO博客,原文鏈接:http://blog.51cto.com/simeon/99759
總結
以上是生活随笔為你收集整理的使用vbs脚本检查网站是否使用asp.net的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IIS 7.5 Express概况
- 下一篇: 关于远程终端不能登录问题解决!