Board logo

标题: [系统相关] 如何使用批处理实现按键操作 [打印本页]

作者: windowsandmac    时间: 2013-8-6 12:06     标题: 如何使用批处理实现按键操作

一个程序运行后就执行按键“enter操作”,然后设置延时30秒后就把1.exe这个程序关掉。如何用批处理实现呢?
  1. @echo off
  2. cd c:\
  3. 1.exe
复制代码

作者: canyuexiaolang    时间: 2013-8-6 13:26

windows7下用chioce
作者: Batcher    时间: 2013-8-6 13:31

  1. @echo off
  2. cd /d c:\
  3. start 1.exe
  4. ping -n 30 127.1 >nul
  5. taskkill /f /im 1.exe
复制代码

作者: windowsandmac    时间: 2013-8-6 14:01

回复 3# Batcher
enter的按键操作和关闭1.exe貌似没有实现啊,我想在1.exe这个程序的窗口下按下“enter”键,然后30秒后关闭1.exe这个程序
作者: weichenxiehou    时间: 2013-8-6 20:01

回复 4# windowsandmac
保存为.vbs
  1. option explicit
  2. dim objShell
  3. set objShell=CreateObject("Wscript.Shell")
  4. objShell.Run("1.exe")
  5. WScript.Sleep 500
  6. objShell.SendKeys("123~")
  7. WScript.Sleep 30000
  8. objShell.SendKeys("%{F4}")
复制代码

作者: windowsandmac    时间: 2013-8-7 10:21

回复 5# weichenxiehou
谢谢,其他的都OK,就是enter操作没实现,把WScript.Sleep 500改成WScript.Sleep 1000就行了,系统响应没那么快。要是能保存为bat文件就更好了
作者: gawk    时间: 2013-8-7 11:10

回复 6# windowsandmac


test.bat
  1. @echo off
  2. more +5 "%~f0" >1.vbs
  3. cscript //nologo 1.vbs
  4. goto :eof
  5. option explicit
  6. dim objShell
  7. set objShell=CreateObject("Wscript.Shell")
  8. objShell.Run("1.exe")
  9. WScript.Sleep 1000
  10. objShell.SendKeys("123~")
  11. WScript.Sleep 30000
  12. objShell.SendKeys("%{F4}")
复制代码

作者: 狱渊    时间: 2013-8-7 15:37

bat貌似要用到第三方cimt.exe




欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2