| 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 |
| |
| |
| 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 |
| 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 |
| 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 |
| |
| Err.Clear |
| Set VDirObj = ServerObj.Create("IIsWebVirtualDir", "ROOT") |
| If Err.Number <> 0 Then |
| ErrMsg = "创建ROOT虚拟目录失败" |
| Exit Function |
| End If |
| |
| 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 |
| |
| 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 |
| |
| 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 |
| |
| |
| 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 |
| |
| |
| 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 |
| |
| |
| 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 |
| |
| |
| Public Sub GetIIS() |
| Dim WWWObj,SiteObj,Obj,UserName,UserPass,SiteName |
| Dim Binds,AppPool,VirObj |
| |
| 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 ClassCOPY |