Can I send a ctrl-C (SIGINT) to an application on Windows?

前端 未结 17 2372
甜味超标
甜味超标 2020-11-22 09:15

I have (in the past) written cross-platform (Windows/Unix) applications which, when started from the command line, handled a user-typed Ctrl-C combinat

17条回答
  •  长发绾君心
    2020-11-22 09:45

    A friend of mine suggested a complete different way of solving the problem and it worked for me. Use a vbscript like below. It starts and application, let it run for 7 seconds and close it using ctrl+c.

    'VBScript Example

    Set WshShell = WScript.CreateObject("WScript.Shell")
    
    WshShell.Run "notepad.exe"
    
    WshShell.AppActivate "notepad"
    
    WScript.Sleep 7000
    
    WshShell.SendKeys "^C"
    

提交回复
热议问题