尝试使用类似这样的东西。使用Process.MainWindowTitle
获得标题文本和Process.CloseMainWindow
关闭用户界面,它比杀死进程更优美。
注:包含做了区分大小写的搜索
Imports System.Diagnostics
Module Module1
Sub Main()
Dim myProcesses() As Process = Process.GetProcesses
For Each p As Process In myProcesses
If p.MainWindowTitle.Contains("Notepad") Then
p.CloseMainWindow()
End If
Next
End Sub
End Module
至于赢API函数尝试这样的事情。请注意,如果您关闭了父母窗口,您还会将关闭。
Module Module1
Private Declare Auto Function FindWindowEx Lib "user32" (ByVal parentHandle As Integer, _
ByVal childAfter As Integer, _
ByVal lclassName As String, _
ByVal windowTitle As String) As Integer
Private Declare Auto Function PostMessage Lib "user32" (ByVal hwnd As Integer, _
ByVal message As UInteger, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Boolean
Dim WM_QUIT As UInteger = &H12
Dim WM_CLOSE As UInteger = &H10
Sub Main()
Dim handle As Integer = FindWindowEx(0, 0, Nothing, "YourFormsTitle")
PostMessage(handle, WM_CLOSE, 0, 0)
End Sub
End Module
感谢您的答复马克,但仍然有问题与您的解决方案。在第一篇文章中看到我的评论 – MiBol
@MiBol所以我按照你所说的来收集,你的过程有多个窗口,你想关闭其中一个窗口而不是另一个窗口? –
没错,但是如果我关闭窗口#2(在图像中),自动关闭窗口#1。如果我手动这样做,这不会发生。 – MiBol