vb 如何判断外部程序是否运行
2个回答
展开全部
我拿任务管理器做实例
你在窗体中创建个timer 和两个cmmandbutton 把下面的代码复制进去直接可以运行
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Sub Command1_Click()
Shell "cmd /c call taskmgr", vbHide
End Sub
Private Sub Command2_Click()
Shell "cmd /c taskkill /im taskmgr.exe", vbHide
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Command1.Caption = "启动"
Command2.Caption = "关闭"
End Sub
Private Sub Timer1_Timer()
Cls
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "windows 任务管理器") ' 取得进程标识符
If hwnd = 0 Then
Print "任务管理器未运行"
Else
Print "任务管理器已运行"
End If
End Sub
你在窗体中创建个timer 和两个cmmandbutton 把下面的代码复制进去直接可以运行
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Sub Command1_Click()
Shell "cmd /c call taskmgr", vbHide
End Sub
Private Sub Command2_Click()
Shell "cmd /c taskkill /im taskmgr.exe", vbHide
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Command1.Caption = "启动"
Command2.Caption = "关闭"
End Sub
Private Sub Timer1_Timer()
Cls
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "windows 任务管理器") ' 取得进程标识符
If hwnd = 0 Then
Print "任务管理器未运行"
Else
Print "任务管理器已运行"
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询