vb code中调用exe文件,当关闭的时候直接关闭文件.

首先,在Module中先声明API函数.
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  Public Const WM_CLOSE = &H10
  Public Const WM_QUIT = &H12

在vb form调用:
启动:
    ShellExecute 112, "open", App.Path & "\TxtToSql.exe", "", "", 0
关闭:
Handle = FindWindow(vbNullString, "TxtToSql")    'TxtToSql是exe的标题(TITLE OR CAPITION)
PostMessage Handle, WM_QUIT, 0&, 0&

你可能感兴趣的:(code)