VBS脚本错误424

时间:2017-01-16 09:42:28

标签: login vbscript

运行登录脚本时收到错误。

事件查看器告诉我:

Starting WSF script v4.0.2 for user nlstebr 16-1-2017 09:57:30
Trigger global user login  W7 Elevated      0 sec.
triggered script: G:\RA\_Automation\Scripting\VBSUnknown error running Sub LaunchAsScheduledTask: strAppPath: 
Error: 424 
Sub LaunchAsScheduledTask(strAppPath)
  '***********************************************************
  ' Running elevated. Create Scheduled Task to launch app.
  '***********************************************************
  '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 

  'The length of time in minutes before the task is automatically deleted
  Const MaxTaskTime = 1 'time in minutes
  '********************************************************
  Dim atb
  Dim wshshell 

  Set wshShell = CreateObject("WScript.Shell")
  atb = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"
  offset = wshShell.RegRead(atb) / 60 'get the time offset from the registry and convert it into the hour offset. This script will probably need modification for non-US locales
  offsetHour = offset Mod 60
  offsetMin = offset \ 60
  If offset < 0 Then
    strOffset = "+" & TwoDigit(offsetHour) & ":" & TwoDigit(offsetMin)
  Else
    strOffset = "-" & TwoDigit(offsetHour) & ":" & TwoDigit(offsetMin)
  End If
  cdt = DateAdd("n",MaxTaskTime,Now()) 'Add time to the current date and time so we can set the trigger expiration to that
  ExpireTime = Year(cdt) & "-" & TwoDigit(Month(cdt)) & "-" & TwoDigit(Day(cdt)) & _
               "T" & TwoDigit(Hour(cdt)) & ":" & TwoDigit(Minute(cdt)) & ":" & TwoDigit(Second(cdt)) & _
               strOffset

  '********************************************************
  ' Create the TaskService object.
  '********************************************************
  Set service = CreateObject("Schedule.Service")
  Call service.Connect()
  strTaskName = "Launch App As Interactive User " & sUser

  '********************************************************
  '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) 
  taskDefinition.Settings.DisallowStartIfOnBatteries = False
  taskDefinition.Settings.StopIfGoingOnBatteries = False
  '********************************************************
  'Create a registration trigger.
  '********************************************************
  Dim triggers
  Set triggers = taskDefinition.Triggers

  Dim trigger
  Set trigger = triggers.Create(TriggerTypeRegistration) 
  trigger.EndBoundary = ExpireTime 'Set the task to expire so it can be deleted automatically

  '***********************************************************
  '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..."

  '***********************************************************
  'Set the settings for the task
  '***********************************************************

  'Dim settings
  Set settings = taskDefinition.Settings
  settings.DeleteExpiredTaskAfter = "PT0M" 'Delete the task immediately after the trigger expires

  '***********************************************************
  'Register (create) the task.
  '***********************************************************
  Call rootFolder.RegisterTaskDefinition(strTaskName, taskDefinition, FlagTaskCreate, , , LogonTypeInteractive)

当我在脚本中添加了使用电池运行的选项时,就会发生这种情况。

0 个答案:

没有答案