如果你可以编辑 .exe 的文件,这里是最简单的方法:
在其中一个 .exe 中添加 FileSystemWatcher 对象并将过滤器设置为特定文件,例如“Commands.txt”
FileSystemWatcher1.Path = Application.StartupPath
FileSystemWatcher1.NotifyFilter=NotifyFilters.LastWrite
FileSystemWatcher1.Filter = "Commands.txt"
FileSystemWatcher1.EnableRaisingEvents = True
要启动/停止监控,请将路径和 EnableRaisingEvents 属性设置为 True 或 False
这是文件更改时引发的事件:
Private Sub FileSystemWatcher1_Changed(sender As System.Object, e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Changed
'Open the file and read the content.
'you can use your own commands
End Sub
这样,您只会在文件更改时收到事件,而无需使用计时器或其他任何东西。
另一个.exe文件,只需要写下你想发送的命令或消息:
此示例每次写入当前日期时间以覆盖文件。
Dim Timestamp() As Byte = System.Text.Encoding.Default.GetBytes(Now.ToString)
Dim Fs As System.IO.FileStream
Fs = New System.IO.FileStream("Commands.txt", FileMode.Create, FileAccess.Write)
Fs.Write(Timestamp, 0, Timestamp.Length - 1)
Fs.Close()
完成!