shIT Admin Blog

Friday, September 01, 2006

Set IIS6.0 In IIS5.0 Isolation Mode (Vbscript)

' This script assumes that IIS is stored in the default location %windir%\system32\inetsrv

' Set constants
Const FOR_READING = "1"
Const FOR_WRITING = "2"

' Declare objects
Set oShell = CreateObject("WScript.Shell")Set oFSO = CreateObject"Scripting.FilesystemObject")

' Assign strings
WinDir = oShell.ExpandEnvironmentStrings("%Windir%")
sStopIIS = "iisreset /stop"
sStartIIS = "iisreset /start"
sIISDisabled = "IIs5IsolationModeEnabled=" & Chr(34) & "FALSE" & Chr(34)
sIISEnabled = "IIs5IsolationModeEnabled=" & Chr(34) & "TRUE" & Chr(34)sMetaBaseXML = sWinDir & "\System32\Inetsrv\Metabase.xml"

' Run iis stop and check return value
iReturnVal = oShell.Run(sStopIIS,1,True)
If iReturnVal <> 0 Then WScript.Echo "Error " & iReturnVal & " occurred when stopping IIS" WScript.Quit
End If

' Open the metabase file in read only mode and assign to variable
Set oMetabaseXMLRead = oFSO.OpenTextFile(sMetaBaseXML,FOR_READING)sAllMetabaseXML = oMetabaseXMLRead.ReadAlloMetabaseXMLRead.Close
Set oMetabaseXMLRead = Nothing
' Open the metabase file in write mode and enable IIS5.0 isolation mode
Set oMetabaseXML = oFSO.OpenTextFile(sMetaBaseXML,FOR_WRITING)
sReplaceText = Replace(sAllMetabaseXML, sIISDisabled, sIISEnabled)oMetabaseXML.WriteLine sReplaceText

' Check that IIS5.0 isolation mode is set to 'TRUE'
iCheckExists = Instr(1,sAllMetabaseXML,sIISEnabled,VbTextCompare)

If iCheckExists <> 0 Then
WScript.Echo "Failed to change IIs5IsolationModeEnabled to 'TRUE' in " & sMetaBaseXML WScript.Quit
End If

'Close the fileoMetabaseXML.Close
Set oMetabaseXML =Nothing

' Run iis start and check return value
iReturnVal = oShell.Run(sStartIIS,1,True)
If iReturnVal <> 0 Then
WScript.Echo "Error " & iReturnVal & " occurred when starting IIS"
WScript.Quit
End If

' Clear down COM objects
Set oShell = Nothing
Set oFSO = Nothing

' If the script has got this far then it was successful
WScript.Echo "Successfully changed IIS into IIS5.0 Isolation Mode"

Sh..IT Admin Blog

Welcome to Sh..IT Admin Blog

This blog is to trap all day to day aspects of Microsoft admin support. My memory is wack so I need something like this to store scripts, reg hacks, optimization and handy tips which otherwise would go into the deep black hole my memory, never to be seen again! :)