VBScript 中的 SendKeys 不适用于 taskmgr [英] SendKeys in VBScript not working for taskmgr

查看:30
本文介绍了VBScript 中的 SendKeys 不适用于 taskmgr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 10 中,我使用完全相同的 vbscript 代码一次用于calc",一次用于taskmgr".为什么 SendKeys(这里是 alt+space)适用于calc"而不适用于taskmgr"?

<job id="vbs"><脚本语言="VBScript">set WshShell = WScript.CreateObject("WScript.Shell")WshShell.Run "calc"WScript.Sleep 100WshShell.SendKeys "% "</工作></包>

(按预期工作,下拉菜单打开)

<job id="vbs"><脚本语言="VBScript">set WshShell = WScript.CreateObject("WScript.Shell")WshShell.Run "taskmgr"WScript.Sleep 100WshShell.SendKeys "% "</工作></包>

(不工作,没有下拉菜单...)

解决方案

我想你错过了第二次按键.对我来说这有效:

DIM 外壳SET shell = WScript.CreateObject("WScript.Shell")shell.Run "taskmgr.exe", 1, FalseWScript.Sleep(100)shell.SendKeys "% "shell.SendKeys "n" '<- 这就是你可能错过的

但它仅在由同一用户运行时才有效(请注意,您不能同时运行两个 taskmgr 实例.当有一个旧"实例时,该实例将被置于前台,而没有新实例将被创建,即使旧"实例在不同的用户下运行.在这种情况下,您可能需要使用 taskkill/im taskmgr.exe

In Windows 10, I am using the exact same vbscript code once for "calc" and once for "taskmgr". Why does SendKeys (here alt+space) work for "calc" but not for "taskmgr"?

<package>
  <job id="vbs">
    <script language="VBScript">
      set WshShell = WScript.CreateObject("WScript.Shell")
      WshShell.Run "calc"
      WScript.Sleep 100
      WshShell.SendKeys "% "
    </script>
  </job>
</package>

(working as expected, drop down menu opens)

<package>
  <job id="vbs">
    <script language="VBScript">
      set WshShell = WScript.CreateObject("WScript.Shell")
      WshShell.Run "taskmgr"
      WScript.Sleep 100
      WshShell.SendKeys "% "
    </script>
  </job>
</package>

(not working, no drop down menu...)

解决方案

I think you missed a second keystroke. For me this works:

DIM shell

SET shell = WScript.CreateObject("WScript.Shell")

shell.Run "taskmgr.exe", 1, False
WScript.Sleep(100)
shell.SendKeys "% "
shell.SendKeys "n" '<- this is what you might have missed

but it only works if run by the same user (note that you cannot have two instances of the taskmgr running at the same time. When there is an "old" instance than this instance will be brought to foreground and no new instance will be created, even if the "old" instance is running under a different user. In this case you might need to close/kill the "old" instance with taskkill /im taskmgr.exe

这篇关于VBScript 中的 SendKeys 不适用于 taskmgr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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