Altiris Software Dev Kit (ASDK)

 View Only

Stopping A Job/Task (Remotely) 

Oct 14, 2015 11:09 AM

I've seen a number on questions raised on connect about whether or not the ASDK web services support the stopping of a job or task. Unfortunately the Task Management Service doesn't support this but the same functionality can be achieved by using the workaround outlined in this article.

The workaround is to have a server task on the notification server which has access to the Altiris assemblies and can stop a given task. The Task Management ASDK service then executes this server task and passes in the job/task instance GUID of the job/task to stop.

Create the Server Task PowerShell Script

1. Create a new Server Task on the Notification server.

2. Set the Script Type to PowerShell

3. Paste the following code content into the task's body.

##
## Load the relevant assemblies from the GAC
##
[reflection.assembly]::LoadWithPartialName("Altiris.TaskManagement")
[reflection.assembly]::LoadWithPartialName("Altiris.TaskManagement.Data")
[reflection.assembly]::LoadWithPartialName("Altiris.TaskManagement.Common")

##
## The Task Instance to stop - The service will pass this in
##
$instance = [Guid]("%!TaskInstance!%")

$TaskInstanceGuid = New-Object -TypeName Altiris.TaskManagement.Common.TaskInstanceGuid -ArgumentList $instance
$taskInstance = [Altiris.TaskManagement.Data.TaskExecutionInstance]::GetTaskInstance($TaskInstanceGuid)

$status = New-Object -TypeName Altiris.TaskManagement.UI.XmlCallback.StopServerTaskInstances+StopStatus

##
## Get the database context
##
$db = [Altiris.NS.ContextManagement.DatabaseContext]::GetContext()

##
## Stop the Job/Task
##
$status.Stopped = $taskInstance.Stop($db, [ref]$status.NonStopped)

4. Press Save Changes.

5. Right-click on the task in the treeview and selecting Properties.

6. Note the task's GUID as we will need this later on. We will use this GUID to tell the Task Management Service to execute this task.

Guid Properties2.JPG

Executing the Task

We now have a task on the NS server which is capable of stopping any job/task instance that is running. This task can now be called remotely using the Task Management Service's ExecuteTask Method.

http://<NSServer>/Altiris/ASDK.Task/TaskManagementService.asmx?op=ExecuteTask

 

Example of Calling the ExecuteTask Method

Below is an example of how you can call the execute task method using PowerShell.

  1. Update the $taskGuid variable to be the GUID of your PowerShell task on the notification server
  2. Updated the $service variable to reflect your notification server.
##
## TASK INSTANCE TO STOP
##
param(
    [parameter(Mandatory=$true)]
    [string]$taskInstance
)

##
## THE POWERSHELL TASK GUID - UPDATE TO REFLECT YOUR POWERSHELL TASK GUID
##
$taskGuid = "5e103b51-f5a4-4b84-9c83-81228b611242"

##
## SERVICE WSDL - UPDATE TO REFLECT YOUR NS
##
$service = "http://<NSServer>/Altiris/ASDK.Task/TaskManagementService.asmx?WSDL"

##
## PROMPT THE USER FOR CREDENTIALS
##
$cred | Out-Null
if($cred -eq $null)
{
    $cred = Get-Credential
}

##
## CREATE A PROXY
##
$proxy = New-WebServiceProxy -uri $service -namespace WebServiceProxy -Credential $cred


##
## BUILD OUR PARAMETER XML
##
$parameter = "<parameter>
        <name>TASKINSTANCE</name>
        <value>$taskInstance</value>
    </parameter>"

##
## CALL OUR POWERSHELL TASK PASSING OVER OUR TASK INSTANCE
##
$proxy.ExecuteTask($taskGuid, "Stop Task!", $parameter)

Now you can remotely stop running jobs and tasks using the ASDK services!

Christopher McEwen
Developer

Protirus

Statistics
0 Favorited
11 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Apr 03, 2019 12:07 PM

I know I'm super late, but I wanted to update everyone and let them know that using an administrator account in Altiris with the "Symantec Administrators" role in Altiris, as well as the "db owner" account in cmdb did the trick. No surprise.

However, I suspect that the only tables the user will need rights on are tables that start with "TaskInstance*", (particularly "TaskInstanceStatus" but haven't gotten to test that yet. I suspect it'll only need UPDATE rights. This is just pure speculation, but for now, I am able to confirm that this works as is. Thanks for your time!

Jan 25, 2019 10:15 AM

Thanks for your quick responses! I'll get back to you when I have this ran with an account with the specified DB rights, or a more powerful user.

Jan 24, 2019 05:16 PM

I can’t remember exactly, having an admin account has made me lazy to the exact permissions,
Whatever the website runs as and match that, should work.
What SQL rights are needed for the application identity?
https://support.symantec.com/en_US/article.HOWTO8320.html

Jan 24, 2019 04:32 PM

The task was originally running with the "local system acccount", which I figured would've been fine. But now that I think about it, I suppose that account probably doesn't have direct access to the database... after changing it to use credentials for another AD SMP account we have handy (but does not have db access to my knowledge), the exception changes to:

 

Exception calling "GetTaskInstance" with "1" argument(s): "Could not load file or assembly 'System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Either a required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)"

... which leads me to believe that this needs to be tried with an account that has access to the database directly. Does this sound correct? If this is the case, is there a list of specific db access rights for this kind of operation (setting a task status to stopped)?

 

Thanks for the links! I was able to register, and I am now am awaiting approval.

Jan 24, 2019 02:52 PM

I’ll need to do some testing as it’s been a while since I looked at the script but the db method should get the context in the same way as the web does so it being on a different server shouldn’t matter.
When the script runs, what account is it using?

Jan 24, 2019 02:44 PM

If you join the following group
SMP
https://www.symantec.com/connect/groups/smp
There’s an SSDK you can request which deals with the server side assemblies
Symantec Solution SDK (SSDK)
https://www.symantec.com/connect/downloads/symantec-solution-sdk-ssdk

Jan 24, 2019 01:24 PM

Alex,

The documentation you specified does not provide any insight to the Altiris.TaskManagement assemblies used in the server-side task script; it does however provide documentation for the Altiris.ASDK.Task namespace (along with the rest of the ASDK documentation). Members such as:

$taskInstance = [Altiris.TaskManagement.Data.TaskExecutionInstance]::GetTaskInstance($TaskInstanceGuid)
$taskInstance.Stop($db, [ref]$status.NonStopped)

are not documented. I was hoping there was direction as to where any server-side assembly documentation might exist.

 

I am also experiencing an exception being thrown in the server side task:

C:\Windows\TEMP\AtrsScriptd58a917b_6663_476c_895c_34173ea81568.ps1 : Exception 
calling "GetTaskInstance" with "1" argument(s): "Failed to construct 
DatabaseContext object. Connection to database failed."
 + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorExcep 
 tion
 + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorExceptio 
 n,AtrsScriptd58a917b_6663_476c_895c_34173ea81568.ps1

Our database is on a separate host. Is there additional configuration required with instantiating this assembly? I would not know, as I cannot find any documentation on these assemblies. Is there any information on what context this database connection is attempting to be instantiated with? i.e.)  where is this database connection information coming from?

The offending line of code appears to be:

	$taskInstance = [Altiris.TaskManagement.Data.TaskExecutionInstance]::GetTaskInstance($TaskInstanceGuid)

The $TaskInstanceGuid should be correct, since we pull that from an Altiris Report that contains a list of Task Instance Guids. Any help you all can provide would be VERY much appreciated, as we would love to implement a remote task-kill feature on our end.

Thanks,

-Codi

 

Sep 18, 2018 02:49 AM

On the SMP Server there should be a Help file (.chm) called "ASDK8.1.chm", with the version number you have installed. This includes documentation on the ASDK Web Services.

Depending on your install location it should be:

"[Install Drive]:\Program Files\Altiris\Altiris ASDK\Help\ASDK8.1.chm"

A couple of folders above there are also Samples

E:\Program Files\Altiris\Altiris ASDK\Samples\

There are also a lot of Articles here on Connect and a dedicated Product Forum page

https://www.symantec.com/connect/product/altiris-software-development-kit-asdk

Sep 17, 2018 04:58 PM

Hi Christopher,

By what means did you come across the documentation to be able to create that server-side script?

thanks,

Scott

Apr 05, 2016 03:34 AM

Hi,

 

How can we acheive same task in python using rest api. Do you have any idea?

Related Entries and Links

No Related Resource entered.