标签归档:IIS Configuration

ADSI管理IIS

使用ADSI获取IIS版本
使用ADSI获取IIS应用程序池列表
使用ADSI获取IIS版本 继续阅读

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!" 

Some examples of scripting of IIS using ADSI, WMI from VB and C# including the new Microsoft.Web.Administration namespace

Below are some simple examples of how to talk to IIS via ADSI, WMI and the new IIS 7 only .NET Managed Provider.

The IIS ADSI Provider

The IIS ADSI provider exposes COM Automation objects that you can use within command-line scripts, ASP pages, or custom applications to change IIS configuration values stored in the IIS metabase. IIS ADSI objects can be accessed and manipulated by any language that supports automation, such as Microsoft® Visual Basic® Scripting Edition (VBScript), Microsoft JScript®, Perl, Microsoft Active Server Pages (ASP), Visual Basic, Java, or Microsoft C++.

继续阅读