Windows 调度程序无法向 putty 发送命令
我以管理员身份登录到winserver2008服务器。
我创建了一个名为:vbscript.vbs 的脚本,
该脚本的目的是通过putty 自动登录linux,然后执行命令行任务。
Dim Shell
Set Shell = CreateObject("WScript.Shell")
output = Shell.Run("C:\putty.exe 1.2.3.4 9321")
wscript.sleep(500)
Shell.Sendkeys "root" & VBCrLf
wscript.sleep(30)
Shell.Sendkeys "password" & VBCrLf
wscript.sleep(30)
当我手动点击vbscript.vbs来执行它时,vbscript会将root和密码填写到putty中。
当我使用 Windows 调度程序调用 vbscript.vbs 来执行它时,vbscript 不会将 root 和密码填写到 putty 中。
我怀疑存在一些权限问题。 我已经将 putty.exe 设置为以管理员身份运行,允许管理员、管理员组权限,但通过 Windows 调度程序调用时仍然无法工作。
=====
我刚刚尝试了第二种情况,将 2 发送到 Windows 计算器,也失败了..
testcalc.vbs
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "Calc.exe"
objShell.AppActivate "Calculator"
objShell.SendKeys "2"
I am logging into the server as Administrator to winserver2008.
I created a script called: vbscript.vbs
The purpose of this script is to auto login to linux via putty, then perform command line task.
Dim Shell
Set Shell = CreateObject("WScript.Shell")
output = Shell.Run("C:\putty.exe 1.2.3.4 9321")
wscript.sleep(500)
Shell.Sendkeys "root" & VBCrLf
wscript.sleep(30)
Shell.Sendkeys "password" & VBCrLf
wscript.sleep(30)
When I manually click on vbscript.vbs to execute it, vbscript will fill in root and password to putty.
When I use windows scheduler call to vbscript.vbs to execute it, vbscript won't fill in root and password to putty.
I suspect some permission issue.
I already set putty.exe to run as administrator, allow administrator, administrators group permission for it, but still fail to work when call via windows scheduler.
=====
I just tried with the second scenario, send 2 to the windows calculator, fail too..
testcalc.vbs
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "Calc.exe"
objShell.AppActivate "Calculator"
objShell.SendKeys "2"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
放弃尝试让
SendKeys
在计划任务中工作,这是不会发生的。相反,只需在命令行上传递登录名和密码即可:或者使用会话文件并使用
-load
来完成此操作。如果您要通过此连接执行命令,那么我相信您实际上需要
plink
而不是putty
。Give up on trying to get
SendKeys
to work from a scheduled task, it's not going to happen. Instead simply pass the login and password on the command line:Alternatively do it with a session file and use
-load
.If you are then going to execute commands over this connection then I believe you actually want
plink
rather thanputty
.