2017-09-12 2 views
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 작업 정의와 옵션을 통해 지정된 작업의 상승 모드에서 작동합니다.

+0

선택적 매개 변수에 대해 Visual Basic 구문을 사용하고 있습니다. VBScript에서는 지원되지 않습니다. 사용하지 않을 선택적 매개 변수에 대해 명시 적으로 'Null'을 전달해야합니다. – IInspectable

+0

@IInspectable : 확실합니까? 그것은 마이크로 소프트의 코드이다. (그 부분과 대부분은 그렇다)? 그들은 Q에서 링크 된 페이지의 "다음 VBScript 예제"로 설명합니다.하지만 시도해 보겠습니다. 감사합니다! :) –

+0

@IInspectable : MS 코드에서 매직 넘버 4는'TASK_LOGON_GROUP'이라고 밝혀졌습니다. 나는 이것을 3,'TASK_LOGON_INTERACTIVE_TOKEN'으로 바꿨고 이제는 작동합니다. 선택적인 args에'Null'을 사용하지 않고, 그 제안에 감사드립니다! –

답변

2

MS 코드의 매직 넘버 4는 TASK_LOGON_GROUP입니다. 나는 이것을 3, TASK_LOGON_INTERACTIVE_TOKEN으로 변경했으며 "Builtin\Administrators" 사용자 ID 대체를 제거했으며 이제는 작동합니다.

관련 문제