You still would probably want to exit if the workdir doesnt exists, I would think... which would produce the same code produced in the post on 2/16/14... WhatchuThink? \:\)

Edit... Opps... added your suggestion of the $workdir without quotes

 Code:
Function RunAsInteractiveUser($KixPath, optional $kixscript, optional $workdir, optional $taskname, optional $donotdelete)
  Dim $service, $rootfolder, $taskdefinition, $triggers,$trigger,$action, $settings
  Dim $TriggerTypeRegistration, $ActionTypeExectuable,$flagtaskcreate,$logontypeinteractive
  if $taskname=""
    $taskname = "Run As Interactive User - " + @ticks
  endif
  $TriggerTypeRegistration = 7
  $ActionTypeExecutable = 0
  $FlagTaskCreate = 2
  $LogonTypeInteractive = 3
  if exist($KixPath)
    $service=CreateObject("Schedule.Service")
    $service.Connect()
    $rootFolder=$service.GetFolder("\")
    $rootFolder.DeleteTask($taskname, 0)
    $taskDefinition = $service.NewTask(0)
    $triggers = $taskDefinition.Triggers
    $trigger = $triggers.Create($TriggerTypeRegistration)
    $settings=$taskDefinition.Settings
    $settings.DisallowStartIfOnBatteries = not 1
    $settings.StopIfGoingOnBatteries = not 1
    $Action = $taskDefinition.Actions.Create($ActionTypeExecutable)
    $Action.Path = $KixPath
    if $kixscript
      if exist($kixscript)
        $Action.Arguments = '"' + $kixscript + '"'
      else
        exit 2
      endif
    endif
    if $workdir
      if exist($workdir)
        $action.WorkingDirectory = $workdir
      else
        exit 2
      endif
    endif
    $rc=$rootFolder.RegisterTaskDefinition($taskname, $taskDefinition, $FlagTaskCreate,,, $LogonTypeInteractive)
    if not $donotdelete
      sleep 1
      $rootFolder.DeleteTask($taskname, 0)
    endif
  else
    exit 2
  endif
endfunction




Edited by Allen (2015-01-09 04:59 PM)