Activer l'action d'écriture du service ACS

Microsoft.SystemCenter.EnableACSAction (WriteActionModuleType)

Active le service ACS.

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
EnableACS WriteAction System.CommandExecuter Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
CollectorServerstring$Config/CollectorServer$Serveur du collecteur

Source Code:

<WriteActionModuleType ID="Microsoft.SystemCenter.EnableACSAction" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element name="CollectorServer" type="xsd:string"/>
<xsd:element name="TargetComputerName" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="CollectorServer" Selector="$Config/CollectorServer$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="EnableACS" TypeID="System!System.CommandExecuter">
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//NoLogo $File/EnableACSAction.vbs$ "$Config/CollectorServer$" "$Target/ManagementGroup/Name$" "$Config/TargetComputerName$"</CommandLine>
<TimeoutSeconds>90</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>EnableACSAction.vbs</Name>
<Contents><Script>

Const HKEY_LOCAL_MACHINE = &amp;H80000002

Set args = WScript.Arguments
strCollectorServer = args.Item(0)
strClientAgentGroup = args.Item(1)
strTargetComputerName = args.Item(2)


WScript.Echo "Agent Management Group: " &amp; strClientAgentGroup

strComputer = "."
strValue = ""

strACSKeyPath = "SOFTWARE\Policies\Microsoft\AdtAgent\Parameters"
strMOMKeyPath = "SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Agent Management Groups\" &amp; strClientAgentGroup &amp; "\Parent Health Services\0"

Set oRegistry = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\default:StdRegProv")

Set oSWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate}\\" &amp; strComputer &amp; "\root\cimv2")

REM The {impersonationLevel=impersonate} clause might not be necessary when running as LocalSystem

strValueName = "LocalConfig"
oRegistry.SetDWORDValue HKEY_LOCAL_MACHINE,strACSKeyPath,strValueName,1

strValueName = "NoCache"
oRegistry.SetDWORDValue HKEY_LOCAL_MACHINE,strACSKeyPath,strValueName,1

if ((strCollectorServer = "[Collector Server]") OR (strCollectorServer = "")) then
strValueName = "NetworkName"
returnCode = oRegistry.GetStringValue(HKEY_LOCAL_MACHINE,strMOMKeyPath,strValueName,Value)

if (returnCode = 2) then
Value = strTargetComputerName
end if

strValueName = "AdtServers"
returnCode = oRegistry.CreateKey(HKEY_LOCAL_MACHINE,strACSKeyPath)
returnCode = oRegistry.SetMultiStringValue(HKEY_LOCAL_MACHINE,strACSKeyPath,strValueName,Array(Value))
else
strValueName = "AdtServers"
arrayCollectorServers = Split(strCollectorServer, ",", -1, 1)
For item = 0 to UBound(arrayCollectorServers)
arrayCollectorServers(item) = Trim(arrayCollectorServers(item))
Next
returnCode = oRegistry.CreateKey(HKEY_LOCAL_MACHINE,strACSKeyPath)
returnCode = oRegistry.SetMultiStringValue(HKEY_LOCAL_MACHINE,strACSKeyPath,strValueName,arrayCollectorServers)
end if

set oService = oSWbemServices.Get("Win32_Service.Name='AdtAgent'")

returnCode = oService.Change(,,,,"Automatic")
WScript.Echo "Service change return code: " &amp; returnCode

stoppedCorrectly = TRUE

if (oService.Started) then
REM we need to stop the service so it can pick up the registry changes

WScript.Echo "Stopping service so it can pick up changes"
returnCode = oService.StopService()

if (NOT returnCode = 0) then
WScript.Echo "Service stop error code: " &amp; returnCode
stoppedCorrectly = FALSE
else
Counter = 6

do while (Counter &gt; 0)
Counter = Counter - 1
returnCode = oService.InterrogateService()
if (returnCode = 6) then
REM
REM 6 means Service Not Active
REM

stoppedCorrectly = TRUE
exit do
elseif (NOT returnCode = 0) then
WScript.Echo "InterrogateService return code: " &amp; returnCode
end if
WScript.Sleep(10000)
loop

if (stoppedCorrectly) then
WScript.Echo "Service stopped correctly"
else
WScript.Echo "Unable to stop Service in 60 seconds"
WScript.Echo "You should manually stop and start the AdtAgent service on the target machine"
end if
end if
end if

if (stoppedCorrectly) then
WScript.Echo "Starting service"
returnCode = oService.StartService()

if (NOT returnCode = 0) then
WScript.Echo "Service was not started correctly"
WScript.Echo "Service start error code: " &amp; returnCode
else
WScript.Echo "Service started correctly"
end if
end if
</Script></Contents>
</File>
</Files>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="EnableACS"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>