我有一个为我提供的cmd行,我不能改变,我需要编写一个脚本,但它有一个build立到它的暂停,我看不到任何方法跳过这个暂停,所以我的脚本的其余部分可以继续。
我尝试了各种各样的东西,包括
@echo | 调用program.exe
program.exe <nul
cmd / c echo y&echo。| Program.exe文件
杰伊的回答在这里
这些的变化和组合
检查程序/? 看看是否有跳过暂停切换,但没有
欣赏任何build议
batch filesearch并将文件名复制到新的TXT文件
如何使用启动命令通过批处理脚本更改命令窗口的颜色
如何在目录path中多次返回?
在^ |上批量字符转义 不工作
如何让F#脚本文件和其他脚本语言像Windows中的.exe,.cmd和.bat文件一样工作
如何在MFC应用程序退出时设置Errorlevel
为什么我的batch file在path中有空格时会出错?
您可以使用interop将数据发送到进程。 这就是所谓的挂钩过程,并且有一些资源。 我喜欢这个答案 。
这是一个允许你发送消息到后台应用程序的小代码。 例如,要发送“A”字符,只需调用sendKeystroke(Keys.A) ,并且不要忘记使用命名空间System.windows.forms能够使用Keys对象。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms; namespace keybound { class WindowHook { [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName,string lpWindowName); [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hWnd,uint Msg,IntPtr wParam,IntPtr lParam); [DllImport("user32.dll")] public static extern IntPtr PostMessage(IntPtr hWnd,IntPtr lParam); public static void sendKeystroke(ushort k) { const uint WM_KEYDOWN = 0x100; const uint WM_SYSCOMMAND = 0x018; const uint SC_CLOSE = 0x053; IntPtr WindowToFind = FindWindow(null,"Untitled1 - Notepad++"); IntPtr result3 = SendMessage(WindowToFind,WM_KEYDOWN,((IntPtr)k),(IntPtr)0); //IntPtr result3 = SendMessage(WindowToFind,WM_KEYUP,((IntPtr)c),(IntPtr)0); } } }
您可能比获取应用程序更容易,而不是搜索过程,因为您可以从应用程序中启动它:
Process proc = new Process(); proc.StartInfo.FileName = executablePath; proc.Start(); proc.WaitForInputIdle();
然后proc.Id将是PID。
作为一种替代方法,我只是遇到了一个VB类型的例子 ,使用Shell函数看起来更简单,但我之前没有使用它。 您需要在应用程序中添加一个暂停等待提示,但是这比Interop看起来更清晰:
Dim ProcID As Integer ' Start the Calculator application,and store the process id. ProcID = Shell("CALC.EXE",AppWinStyle.normalFocus) ' Activate the Calculator application. AppActivate(ProcID) ' Send the keystrokes to the Calculator application. My.Computer.Keyboard.SendKeys("22",True) My.Computer.Keyboard.SendKeys("*",True) My.Computer.Keyboard.SendKeys("44",True) My.Computer.Keyboard.SendKeys("=",True) ' The result is 22 * 44 = 968.
如果发生System.ArgumentException ,可能是因为Shell函数没有获得进程ID。 这是因为它需要完全信任。 如果以管理员身份运行,应用程序将工作 我不认为你会找到一个简单的方法,如果你不能这样做,因为这是一个安全问题,让应用程序相互运行,但我可能是错的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。