' Set up variables:
Set IIsWebServiceObj = GetObject("IIS://localhost/W3SVC")
Set IIsWebServerObj = GetObject("IIS://localhost/W3SVC/1")
Dim sClsidNCSA
Dim sClsidIIS
Dim sClsidW3C
Dim sLogPluginClsid
Dim sNCSA
Dim sIIS
Dim sW3C
sNCSA = "NCSA Common Log File Format"
sIIS = "Microsoft IIS Log File Format"
sW3C = "W3C Extended Log File Format"
' List the available logging formats:
WScript.Echo("Available logging formats are " & IIsWebServiceObj.LogModuleList)
' Identify the Clsids of each logging module:
Set IIsLogModuleObj = GetObject("IIS://localhost/Logging/" & sNCSA)
sClsidNCSA = IIsLogModuleObj.LogModuleId
Set IIsLogModuleObj = GetObject("IIS://localhost/Logging/" & sIIS)
sClsidIIS = IIsLogModuleObj.LogModuleId
Set IIsLogModuleObj = GetObject("IIS://localhost/Logging/" & sW3C)
sClsidW3C = IIsLogModuleObj.LogModuleId
' Get the logging format that is currently set for the default Web site:
sLogPluginClsid = IIsWebServerObj.LogPluginClsid
If (sLogPluginClsid = sClsidNCSA) Then
WScript.Echo("Log type is " & sNCSA)
Elseif (sLogPluginClsid = sClsidIIS) Then
WScript.Echo("Log type is " & sIIS)
Elseif (sLogPluginClsid = sClsidW3C) Then
WScript.Echo("Log type is " & sW3C)
Else WScript.Echo("Log type is not one of the IIS provided types")
End If
WScript.Echo("LogExtFileFlags = " & IIsWebServerObj.LogExtFileFlags )
' Enable logging:
If Not (IIsWebServerObj.LogType = 1) Then
IIsWebServerObj.Put "LogType", 1
IIsWebServerObj.SetInfo
WScript.Echo("Had to enable logging")
End If
' Set the logging format to W3C Extended:
IIsWebServerObj.Put "LogPluginClsid", sClsidW3C
' Log only the client IP address, the HTTP status, the time, and the URL.
IIsWebServerObj.Put "LogExtFileClientIp", True
IIsWebServerObj.Put "LogExtFileHttpStatus", True
IIsWebServerObj.Put "LogExtFileTime", True
IIsWebServerObj.Put "LogExtFileUriStem", True
IIsWebServerObj.Put "LogExtFileMethod", False
IIsWebServerObj.Put "LogExtFileDate", False
IIsWebServerObj.Put "LogExtFileUserName", False
IIsWebServerObj.Put "LogExtFileServerIp", False
IIsWebServerObj.Put "LogExtFileUriQuery", False
IIsWebServerObj.Put "LogExtFileWin32Status", False
IIsWebServerObj.Put "LogExtFileServerPort", False
IIsWebServerObj.Put "LogExtFileUserAgent", False
' Uncomment the next line for IIS 6.0:
'IIsWebServerObj.Put "LogExtFileHttpSubStatus", False
IIsWebServerObj.SetInfo
WScript.Echo("Logging has been changed to W3C Extended")
' See what the new value is:
IIsWebServerObj.GetInfo
sLogPluginClsid = IIsWebServerObj.LogPluginClsid
If (sLogPluginClsid = sClsidNCSA) Then
WScript.Echo("Log type is " & sNCSA)
Elseif (sLogPluginClsid = sClsidIIS) Then
WScript.Echo("Log type is " & sIIS)
Elseif (sLogPluginClsid = sClsidW3C) Then
WScript.Echo("Log type is " & sW3C)
Else WScript.Echo("Log type is not one of the IIS provided types")
End If
WScript.Echo("LogExtFileFlags = " & IIsWebServerObj.LogExtFileFlags )