Public Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" () As String
'Project1.exe Private sub Comman1_click() Shell "Project2.exe 你好" End Sub'Project2.exe Sub Main() Msgbox command() End Sub
例子: 第一个exe文件只有一个窗体,窗体上有一个textbox控件text1 代码: Option Explicit Private Sub Text1_Change() If Len(Text1.Text) = 3 Then MsgBox Text1.Text End If End Sub 第二个exe文件也只有一个窗体,代码如下: Option ExplicitPrivate Sub Form_Load() Shell App.Path & "\test.exe", vbNormalFocus SendKeys "myh", TrueEnd Sub 运行第二个exe将调用第一个exe文件,发送“myh”到第一个exe中,第一个exe将执行Text1_Change()事件,弹出对话框
如果想保证两个EXE同时运行 又能传递数值。最好采用共享内存的方式。
shell
findwindow后,发送消息参考一下
http://www.mydown.com/code/116/116442.html
在第二个exe中调用API GetEnvironmentVariable吧
Private sub Comman1_click()
Shell "Project2.exe 你好"
End Sub'Project2.exe
Sub Main()
Msgbox command()
End Sub
第一个exe文件只有一个窗体,窗体上有一个textbox控件text1
代码:
Option Explicit
Private Sub Text1_Change()
If Len(Text1.Text) = 3 Then
MsgBox Text1.Text
End If
End Sub
第二个exe文件也只有一个窗体,代码如下:
Option ExplicitPrivate Sub Form_Load()
Shell App.Path & "\test.exe", vbNormalFocus
SendKeys "myh", TrueEnd Sub
运行第二个exe将调用第一个exe文件,发送“myh”到第一个exe中,第一个exe将执行Text1_Change()事件,弹出对话框