0
を経由してログオンタスクをスケジュールするにはどうすればMicrosoft's exampleのバリエーションの数を試してみました。何も働かなかった。次のコードは、それが現在のように見える、と(下記参照)に動作しないというものです:ユーザーに何か問題がありますVBScriptの
option explicit
'********************************************************
' Create the TaskService object.
Dim service
Set service = CreateObject("Schedule.Service")
call service.Connect()
'********************************************************
' Get a folder to create a task definition in.
Dim rootFolder
Set rootFolder = service.GetFolder("\")
' The taskDefinition variable is the TaskDefinition object.
Dim taskDefinition
' The flags parameter is 0 because it is not supported.
Set taskDefinition = service.NewTask(0)
'----------------- principal
' taskDefinition.principal.LogonType = 3
' taskDefinition.principal.UserId = "S-1-5-21-2764009396-4153354299-2297777058-1001"
' taskDefinition.principal.RunLevel = 0 ' Least privilege
' taskDefinition.principal.GroupId = "Builtin\Administrators"
'********************************************************
' Define information about the task.
' Set the registration info for the task by
' creating the RegistrationInfo object.
Dim regInfo
Set regInfo = taskDefinition.RegistrationInfo
regInfo.Description = "Task will execute Notepad when a " & _
"specified user logs on."
regInfo.Author = "Author Name"
' Set the task setting info for the Task Scheduler by
' creating a TaskSettings object.
Dim settings
Set settings = taskDefinition.Settings
settings.StartWhenAvailable = True
'********************************************************
' Create a logon trigger.
' A constant that specifies a logon trigger.
const TriggerTypeLogon = 9
Dim triggers
Set triggers = taskDefinition.Triggers
Dim trigger
Set trigger = triggers.Create(TriggerTypeLogon)
' Trigger variables that define when the trigger is active.
Dim startTime, endTime
startTime = "2006-05-02T10:49:02"
endTime = "2046-05-02T10:52:02"
'WScript.Echo "startTime :" & startTime
'WScript.Echo "endTime :" & endTime
trigger.StartBoundary = startTime
trigger.EndBoundary = endTime
trigger.ExecutionTimeLimit = "PT5M" ' Five minutes
trigger.Id = "LogonTriggerId"
trigger.UserId = "alfp" ' "alfswindowspc10\alfp" ' Must be a valid user account
trigger.Enabled = True
'***********************************************************
' Create the action for the task to execute.
' A constant that specifies an executable action.
const ActionTypeExecutable = 0
' Add an action to the task. The action executes notepad.
Dim Action
Set Action = taskDefinition.Actions.Create(ActionTypeExecutable)
Action.Path = "C:\Windows\System32\notepad.exe"
WScript.Echo "Task definition created. About to submit the task..."
'***********************************************************
' Register (create) the task.
const createOrUpdateTask = 6
call rootFolder.RegisterTaskDefinition(_
"Test Logon Trigger", taskDefinition, createOrUpdateTask, _
"Builtin\Administrators", , 4)
WScript.Echo "Task submitted."
すべての試みは、これまで明らかに主張し、最後にrootFOlder.RegisterTaskDefinition
呼び出しでクラッシュしましたid、または代わりにグループidを使用します。
[C:\my\tezt]
> cscript //e:vbscript //nologo example_create_task.vbs
Task definition created. About to submit the task...
C:\my\tezt\example_create_task.vbs(88, 5) (null): (42,4):GroupId:
[C:\my\tezt]
>_
通常モードまたは昇格モードのどちらで実行しても問題ありません。 schtasks
コマンドを使用してログオンタスクのスケジュール
は、XMLタスク定義のための、およびオプションで指定タスクの昇格モードから、一般的に動作します。
あなたは、オプションのパラメータのためのVisual Basicの構文を使用しています。これはVBScriptではサポートされていません。あなたは、使用しないオプションのパラメータに 'Null'を明示的に渡す必要があります。 – IInspectable
@IInspectable:本当ですか?それはマイクロソフトのコードです(さて、その部分とそれの大部分です)。彼らはQでリンクされたページの "次のVBScriptの例"としてそれを記述します。しかし、私は試してみます、ありがとう! :) –
@IInspectable:これは、MSコードにマジックナンバー4は 'TASK_LOGON_GROUP'たことが判明しました。私はそれを3に変更しました、 'TASK_LOGON_INTERACTIVE_TOKEN'、そして今は動作します。オプションのargsに 'Null'を使わずに、その提案に感謝します! –