下面土嘎嘎小编分享一个示例的 VB6 代码片段,用于检测同一目录下是否有名为 "B.exe" 的进程正在运行:
〓〓vb代码如下:〓〓
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Function IsProcessRunning(ByVal processName As String) As Boolean
Dim hwnd As Long
hwnd = FindWindow(vbNullString, processName)
If hwnd <> 0 Then
IsProcessRunning = True
Else
IsProcessRunning = False
End If
End Function
Private Sub CheckBEXE()
Dim bExePath As String
Dim bExeRunning As Boolean '获取当前路径下 B.exe 的完整路径
bExePath = App.Path & "\B.exe" '检测 B.exe 是否正在运行
bExeRunning = IsProcessRunning(bExePath)
If bExeRunning Then
MsgBox "B.exe 正在运行。"
Else
MsgBox "B.exe 未在运行。"
End If
End Sub
你可以将以上代码添加到你的 VB6 项目中,并在需要的地方调用 CheckBEXE 这个子过程,它会根据同一目录下的 "B.exe" 文件的运行情况弹出相应的消息框。