当有进程进入任务管理器时VB怎样能获取其进程名称 10
展开全部
先给你思路:一,找到要关闭的窗体名称,然后关闭,找不到就不管
二,第一次遍历当前所有进程,保存所有进程, 每1秒钟或几秒钟检测是否有新的进程,然后关闭要指定的进程.
下面是第一方法, 第二方法.......要好些.但看要求好像用不到! 所以没发!
'需要控件:command1,text1,timer1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE = &H10
Function CloseFrm(sFrmTitle As String) As String
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, sFrmTitle) '标题为form11,大小写无所谓
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then CloseFrm = "置入消息错误!"
Else
CloseFrm = sFrmTitle & " 没有找到或没有打开或已经被关闭了!"
End If
End Function
Private Sub Command1_Click()
Timer1.Interval = IIf(Command1.Caption = "开始监控", 1000, 0) '每一秒钟关闭指定程序
Command1.Caption = IIf(Command1.Caption = "开始监控", "暂停监控", "开始监控")
End Sub
Private Sub Form_Load()
Text1.Text = "计算器"
Command1.Caption = "开始监控"
End Sub
Private Sub Timer1_Timer()
Me.Caption = CloseFrm(Text1.Text)
End Sub
二,第一次遍历当前所有进程,保存所有进程, 每1秒钟或几秒钟检测是否有新的进程,然后关闭要指定的进程.
下面是第一方法, 第二方法.......要好些.但看要求好像用不到! 所以没发!
'需要控件:command1,text1,timer1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE = &H10
Function CloseFrm(sFrmTitle As String) As String
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, sFrmTitle) '标题为form11,大小写无所谓
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then CloseFrm = "置入消息错误!"
Else
CloseFrm = sFrmTitle & " 没有找到或没有打开或已经被关闭了!"
End If
End Function
Private Sub Command1_Click()
Timer1.Interval = IIf(Command1.Caption = "开始监控", 1000, 0) '每一秒钟关闭指定程序
Command1.Caption = IIf(Command1.Caption = "开始监控", "暂停监控", "开始监控")
End Sub
Private Sub Form_Load()
Text1.Text = "计算器"
Command1.Caption = "开始监控"
End Sub
Private Sub Timer1_Timer()
Me.Caption = CloseFrm(Text1.Text)
End Sub
大雅新科技有限公司
2024-11-19 广告
2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询