标签归档:ServerBindings

ADSI 更新IIS绑定IP

用ADSI更新服务器IP

Option Explicit  
On Error Resume Next 
 
Dim objIIS  
Dim objSite  
Dim varBindings  
Dim intBindings  
Dim blnChanged  
 
Const strOldIP = "10.0.0.1" 
Const strNewIP = "192.168.0.1" 
 
Set objIIS = GetObject("IIS://LOCALHOST/W3SVC")  
 
If (Err <> 0) Then 
  WScript.Echo "Error " & Hex(Err.Number) & "(" & _  
    Err.Description & ") occurred." 
  WScript.Quit  
Else 
  For Each objSite In objIIS  
    blnChanged = False 
    If objSite.class = "IIsWebServer" Then 
      varBindings = objSite.ServerBindings  
      For intBindings = 0 To UBound(varBindings)  
        If InStr(varBindings(intBindings),strOldIP) Then 
          blnChanged = True 
          varBindings(intBindings) = Replace(varBindings(intBindings),strOldIP,strNewIP)  
        End If 
      Next 
    End If 
    If blnChanged = True Then 
      objSite.ServerBindings = varBindings        
      objSite.Setinfo  
    End If 
  Next 
End If 
MsgBox "Finished!"