Restart Internet Information Services

Microsoft.SystemCenter.Apm.Infrastructure.Monitoring.ApmAgent.RestartIIS.Task (Task)

This task restarts Internet Information Services on target computers.

Element properties:

TargetMicrosoft.SystemCenter.Apm.ApmAgent
AccessibilityInternal
CategoryMaintenance
EnabledTrue
RemotableFalse
Timeout300

Member Modules:

ID Module Type TypeId RunAs 
WA1 WriteAction Microsoft.Windows.ScriptWriteAction System.PrivilegedMonitoringAccount

Source Code:

<Task ID="Microsoft.SystemCenter.Apm.Infrastructure.Monitoring.ApmAgent.RestartIIS.Task" Accessibility="Internal" Enabled="true" Target="AI!Microsoft.SystemCenter.Apm.ApmAgent" Remotable="false">
<Category>Maintenance</Category>
<WriteAction ID="WA1" TypeID="Windows!Microsoft.Windows.ScriptWriteAction" RunAs="System!System.PrivilegedMonitoringAccount">
<ScriptName>ActivatedApmAgent.RestartIIS.Task.vbs</ScriptName>
<Arguments/>
<ScriptBody><Script>

Option Explicit

SetLocale("en-us")

Const commandLine = "%WINDIR%\SYSTEM32\IISRESET.EXE /RESTART"

Dim WShell : Set WShell = CreateObject("wscript.shell")
Dim oExec : Set oExec = WShell.Exec(commandLine)
Do While oExec.Status = 0
WScript.Sleep 100
Loop

If Not oExec.StdOut.AtEndOfStream Then
Dim stdOutput : stdOutput = "" &amp; oExec.StdOut.ReadAll()
End If
Dim execResult : execResult = oExec.ExitCode

' Write error output and exit if result is not 0
If 0 &lt;&gt; execResult Then
Wscript.StdErr.Write stdOutput
Wscript.Quit execResult
End If

Dim oAPI : Set oAPI = CreateObject("MOM.ScriptAPI")
Call oAPI.LogScriptEvent("ActivatedApmAgent.RestartIIS.Task.vbs", 3202, 0, "Restart IIS task done.")

Wscript.StdOut.Write stdOutput
Wscript.Quit execResult

On Error Resume Next
Wscript.StdErr.Write Err.Description
Wscript.Quit Err.Code

</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</WriteAction>
</Task>