修改vbs代码以添加更多任务计划选项 [英] modify vbs code to add more task scheduled options

查看:438
本文介绍了修改vbs代码以添加更多任务计划选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何修改此脚本以添加这两个功能:

1-以最高权限运行

2-电源选项有电池和交流电。如何让它在两者上运行?如果这很难,那就不重要

 ' 此示例计划在用户登录时启动notepad.exe的任务。 
' - -------------------------------------------------- ------

' 一个指定登录触发器的常量。
const TriggerTypeLogon = 9
' 一个指定可执行操作的常量。
const ActionTypeExecutable = 0

const TASK_LOGON_INTERACTIVE_TOKEN = 3

' ********* ********** *************************************
' 创建TaskService对象。
设置 service = CreateObject( Schedule.Service
致电 service.Connect()

' ******* **************
' 获取一个文件夹以在中创建任务定义。
Dim rootFolder
设置 rootFolder = service.GetFolder( \

' taskDefinition变量是TaskDefinition对象。
Di m taskDefinition
' flags参数为0,因为它不受支持。
设置 taskDefinition = service.NewTask( 0

< span class =code-comment>' ************************** ******************************
' 定义有关任务的信息。

' 通过设置任务的注册信息
' 创建RegistrationInfo对象。
Dim regInfo
设置 regInfo = taskDefinition.RegistrationInfo
regInfo.Description = 任务将执行Notepad wh一个& _
指定的用户登录。
regInfo.Author = 作者姓名

' 按任务计划程序设置任务设置信息
' 创建TaskSettings对象。
Dim 设置
设置 settings = taskDefinition.Settings
settings.StartWhenAvailable = True

' *********************************** *********************
' 创建一个登录触发器。
Dim 触发
设置 triggers = taskDefin ition.Triggers

Dim 触发
设置 trigger =触发器。 Create(TriggerTypeLogon)


trigger.ExecutionTimeLimit = PT5M ' 五分钟
trigger.Id = LogonTriggerId
trigger.UserId = ' 必须是有效的用户帐户

' *********************** ************************************
' 为要执行的任务创建操作。

' 添加一个这个任务。该操作执行记事本。
Dim 操作
设置操作= taskDefinition.Actions.Create(ActionTypeExecutable)
Action.Path = C:\ Windows \ System32 \\ \\ notepad.exe

WScript.Echo 已创建任务定义。提交任务...

' ***** ************************************************** ****
' 处理密码问题

taskDefinition.Principal.UserId =
taskDefinition.Principal.LogonType = TASK_LOGON_INTERACTIVE_TOKEN

' **************** ******** ***********************************
' 注册(创建)任务。
const createOrUpdateTask = 6
call rootFolder.RegisterTaskDefinition(_
测试登录触发器,taskDefinition,createOrUpdateTask,_
空,空,TASK_LOGON_INTERACTIVE_TOKEN)

WScript.Echo 提交任务。

解决方案

你需要在这里添加taskDefinition.Principal.RunLevel并将其设置为



'TASK_RUNLEVEL_TYPE

Const TASK_RUNLEVEL_LUA = 0

Const TASK_RUNLEVEL_HIGHEST = 1



重要提示:如果您使用最高权限,脚本需要运行提升!



 '  ******** ************************************************** *  
' 处理密码问题

taskDefinition.Principal.UserId =
taskDefinition.Principal.LogonType = TASK_LOGON_INTERACTIVE_TOKEN

taskDefinition.Principal.RunLevel = TASK_RUNLEVEL_HIGHEST ' TASK_RUNLEVEL_TYPE


How to modify this script to add this two functions :
1- run with highest privileges
2- the power option there is battery and ac. How to make it run on both? If this is hard okay, it's not important

' This sample schedules a task to start notepad.exe when a user logs on.
'---------------------------------------------------------

' A constant that specifies a logon trigger.
const TriggerTypeLogon = 9
' A constant that specifies an executable action.
const ActionTypeExecutable = 0   

const TASK_LOGON_INTERACTIVE_TOKEN = 3

'********************************************************
' Create the TaskService object.
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) 

'********************************************************
' 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.
Dim triggers
Set triggers = taskDefinition.Triggers

Dim trigger
Set trigger = triggers.Create(TriggerTypeLogon)


trigger.ExecutionTimeLimit = "PT5M"    ' Five minutes
trigger.Id = "LogonTriggerId"
trigger.UserId = ""   ' Must be a valid user account   

'***********************************************************
' Create the action for the task to execute.

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

'***********************************************************
' Deal with the password problems

taskDefinition.Principal.UserId = ""
taskDefinition.Principal.LogonType = TASK_LOGON_INTERACTIVE_TOKEN

'***********************************************************
' Register (create) the task.
const createOrUpdateTask = 6
call rootFolder.RegisterTaskDefinition( _
    "Test Logon Trigger", taskDefinition, createOrUpdateTask, _
    Empty , Empty, TASK_LOGON_INTERACTIVE_TOKEN)

WScript.Echo "Task submitted."

解决方案

You need to add here "taskDefinition.Principal.RunLevel" and set it to

' TASK_RUNLEVEL_TYPE
Const TASK_RUNLEVEL_LUA = 0
Const TASK_RUNLEVEL_HIGHEST = 1

IMPORTANT: If you use Highest Privilege, the script will need to run elevated!

'***********************************************************
' Deal with the password problems

taskDefinition.Principal.UserId = ""
taskDefinition.Principal.LogonType = TASK_LOGON_INTERACTIVE_TOKEN

taskDefinition.Principal.RunLevel = TASK_RUNLEVEL_HIGHEST ' TASK_RUNLEVEL_TYPE


这篇关于修改vbs代码以添加更多任务计划选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆