'======================================================================================
' The sample script is provided as an example only. It is not tested and is not 
' warranted in any way by Intel; Intel disclaims any liability in connection therewith. 
' Intel does not provide technical support with regard to this scripting. For more 
' information on scripting, refer to applicable Microsoft documentation. 
'======================================================================================

Public ServerIPAddress
Public HeartBeatEnable
Public OsHangWatchdogEnable
Public SelectedAdapter
Public SNMPCommunity
Public EnableAllRemoteCtrlFunctions

<job id="main">
	<script language="VBScript">
		Dim Services
		Dim MyObject

		' Set values that will be used in this script
	
		' Set this value to your management console IP address
		ServerIPAddress="143.185.2.27"

		' Set this value to TRUE to enable Heartbeat sending
		HeartBeatEnable = TRUE

		' Set this value to TRUE to enable OS hang watchdog
		OsHangWatchdogEnable = TRUE

		' Set this value to the SNMP community string
		SNMPCommunity="public"
	
		' Set this value to 1 to enable all remote control functions, 0 to disable all
		EnableAllRemoteCtrlFunctions = 0

		' set this value to "" for adapter auto selection 
		SelectedAdapter=""
		

		
		'WScript.Echo "Running Script to configure Intel ASF"	
		
		'
		'Connect to system	
		'
		Connect_Server()
		If IsObject(Services) = FALSE Then
			WScript.Echo "Exiting VBScript"
			WScript.Quit
		End If
		
		'
		'Get Intel ASF WMI Object and set configuration data
		'
		Get_Object()
		If IsObject(MyObject) = FALSE Then
			WScript.Echo "Exiting VBScript"
			WScript.Quit
		End If
		
		'
		'to debug: uncomment the next line to read configured data and display it.
		'
		'Refresh_Data()
		'
		'Exit the script
		'
		'WScript.Echo "Exiting Script"
		
		'****************************************************************************
		'SUB ROUTINES USED IN THE SCRIPT
		'****************************************************************************
		'****************************************************************************
		' This subroutine connects to the local host
		'****************************************************************************
		Sub Connect_Server()
			On Error Resume Next

			'WScript.Echo ("Connecting to Local System system.")
			Set Services = CreateObject("Wbemscripting.SWbemLocator").ConnectServer( ,"root\cimv2")
			If (IsObject(Services) = FALSE) Then
				WScript.Echo Err.Description
				Exit Sub
			End If
			'WScript.Echo "Connected"
		End Sub
		
		
		'****************************************************************************
		'This sub routine creates an intance of CIM class that models Intel ASF 
		'Alert Sending Device. The routine then sets the ASD parameters (alert destination,
		'enable heartbeats, enable OS hang watchdog, selected adapter, SNMP community and
		'enabled remote control functions) 
		'****************************************************************************
		Sub Get_Object()
			On Error Resume Next

			set MyObject = Services.Get("IA_ASF_OOBAlertService.Name='Intel ASF OOB Alert Service'")
			If IsObject(MyObject) = FALSE Then
					WScript.Echo "Intel ASF Alert Service is not present in the system" 
					Exit Sub
			End If
			
			' Set values
			MyObject.DestinationAddress = ServerIPAddress
			MyObject.EnablePresenceHeartbeats = HeartBeatEnable
			MyObject.SelectedAdapter=SelectedAdapter
			MyObject.SNMP_Community = SNMPCommunity

			' Remote control functions
			if EnableAllRemoteCtrlFunctions = 1 Then

				' first, disable all the currently enabled functions
				for i=0 to UBound (MyObject.EnabledFunctions)
					MyObject.EnabledFunctions(i) = ""
				next								

				' enable all supported functions
				for i=0 to UBound (MyObject.SupportedFunctions)
					MyObject.EnabledFunctions(i) = MyObject.SupportedFunctions(i)				
				next				

			Else
				' disable all functions
				for i=0 to UBound (MyObject.EnabledFunctions)
					MyObject.EnabledFunctions(i) = ""
				next								
			End if			

			MyObject.Enable = True
			MyObject.Put_

		
			' for OS hang Watchdog, use the watchdog class
			set MyObject = Services.Get("IA_ASF_WatchDog.DeviceID='Intel ASF OOB Alert Service WatchDog'")
			If IsObject(MyObject) = FALSE Then
				WScript.Echo "Intel ASF Alert Service Watchdog is not present in the system" 
				Exit Sub
			End If
			MyObject.WatchdogEnable =  OsHangWatchdogEnable
			MyObject.Put_

		End Sub
	
		
		'****************************************************************************
		'This sub routine creates an instance of CIM class that models Intel ASF 
		'Alert Sending Device. Routine reads the current configuration and displays
		'status of ASF
		'****************************************************************************
		Sub Refresh_Data()	
			set MyObject = Services.Get("IA_ASF_OOBAlertService.Name='Intel ASF OOB Alert Service'")
			If ( MyObject.SafeMode) Then
				Dim Answer
				Answer = MsgBox ("ASF Agent is in SAFE MODE!" &Chr(13) & MyObject.ReasonForSafeMode, 16, "Intel ASF Configuration")
				Exit Sub
			Else
				WScript.Echo "ASF Configured"
			End If
			WScript.Echo "Server IP address: " & MyObject.DestinationAddress
			WScript.Echo "Adapter IP Address: " & MyObject.IPAddress	
			WScript.Echo "System ID: " & MyObject.SystemID	
		End Sub
					
	</script>
</job>