Jump to content

[VB Script] - Deleteion of Task in Scheduler


Recommended Posts

We are running 2 Vista machines in a Windows 2003 domain environment. We are having issues with the login scripts like everyone else. We think for our scenario that we might have it fixed but we cant seem to figure out this last part. We have the "launchapp.wsf" all created and working. In doing so, this script creates a new task in the task scheduler. This works perfect for admins but doesnt work at all for non-admins.

Is it possible to VB into the launchapp.wsf file to tell the task scheduler that once this script has run, to DELETE the task from the scheduler? I don't want it to stop, i want it DELETED. Is there anyway to encode this?

Here is the code:

<job>

<script language="VBScript">

'---------------------------------------------------------

' This sample launches the application as interactive user.

'---------------------------------------------------------

' A constant that specifies a registration trigger.

const TriggerTypeRegistration = 7

' A constant that specifies an executable action.

const ActionTypeExecutable = 0

' A constant that specifies the flag in RegisterTaskDefinition.

const FlagTaskCreate = 2

' A constant that specifies an executable action.

const LogonTypeInteractive = 3

' A constant that specifies the flag in RegisterTaskDelection.

const FlagTaskDelete = 2

If WScript.Arguments.Length <> 1 Then

WScript.Echo "Usage: cscript launchapp.wsf <AppPath>"

WScript.Quit

End If

strAppPath = WScript.Arguments(0)

'********************************************************

' Create the TaskService object.

'********************************************************

Set WshNetwork = WScript.CreateObject("WScript.Network")

Set service = CreateObject("Schedule.Service")

call service.Connect()

strTaskName = "Launch App As Interactive User for " & WshNetwork.UserName

'********************************************************

' Get a folder to create a task definition in.

'********************************************************

Dim rootFolder

Set rootFolder = service.GetFolder("\")

'Delete the task if already present

On Error Resume Next

call rootFolder.DeleteTask(strTaskName, 0)

Err.Clear

'********************************************************

' Create the new task

'********************************************************

Dim taskDefinition

Set taskDefinition = service.NewTask(0)

'********************************************************

' Create a registration trigger.

'********************************************************

Dim triggers

Set triggers = taskDefinition.Triggers

Dim trigger

Set trigger = triggers.Create(TriggerTypeRegistration)

'***********************************************************

' Create the action for the task to execute.

'***********************************************************

' Add an action to the task. The action executes the app.

Dim Action

Set Action = taskDefinition.Actions.Create( ActionTypeExecutable )

Action.Path = strAppPath

WScript.Echo "Task definition created. About to submit the task..."

'***********************************************************

' Register (create) the task.

'***********************************************************

call rootFolder.RegisterTaskDefinition(strTaskName, taskDefinition, FlagTaskCreate,,, LogonTypeInteractive)

WScript.Echo "Task submitted."

</script>

</job>

Edited by theorist80
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...