Eliminate psexec altogether. Use schtasks to create a task that runs schtasks via the System account, like this:
If WScript.Arguments.length = 0 Then
Set objShell = CreateObject("Shell.Application")
'Pass a bogus argument, say [ uac]
objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
Set oWSH = WScript.CreateObject("WScript.Shell")
TR = "schtasks /change /tn '\Microsoft\Windows\WindowsUpdate\sihpostreboot' /disable"
oWSH.Run "schtasks /create /ru system /tn CustomTask /tr """ & TR & """ /sc onevent /ec system /mo *[System/EventID=999] /f",0,True
oWSH.Run "schtasks /run /tn CustomTask",0,False
End If
Note that the OnEvent entry is just a dummy event to allow us to create the scheduled task.
Also note the single quotes in the TR = string. That's an Schtasks feature, not a VBScript feature. Schtasks converts those single quotes to double quotes when it creates the task, allowing for a command that has arguments with spaces.
发布评论
评论(1)
完全消除PSEXEC。使用schtask创建一个通过系统帐户运行SCHTASK的任务,例如:
请注意,
OneVent
条目只是一个虚拟事件,可以允许我们创建计划的任务。还请注意
tr =
字符串中的单个引号。那是schtasks
功能,而不是vbscript功能。 Schtasks创建任务时将这些单引号转换为双引号,从而允许具有带有空格参数的命令。Eliminate psexec altogether. Use schtasks to create a task that runs schtasks via the System account, like this:
Note that the
OnEvent
entry is just a dummy event to allow us to create the scheduled task.Also note the single quotes in the
TR =
string. That's anSchtasks
feature, not a VBScript feature. Schtasks converts those single quotes to double quotes when it creates the task, allowing for a command that has arguments with spaces.