从VBScript运行PSEXEC到Windows 10上的计划任务,然后隐藏控制台窗口

发布于 2025-01-17 13:36:54 字数 1398 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も星光 2025-01-24 13:36:54

完全消除PSEXEC。使用schtask创建一个通过系统帐户运行SCHTASK的任务,例如:

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

请注意,OneVent条目只是一个虚拟事件,可以允许我们创建计划的任务。

还请注意tr =字符串中的单个引号。那是schtasks功能,而不是vbscript功能。 Schtasks创建任务时将这些单引号转换为双引号,从而允许具有带有空格参数的命令。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文