System.Diagnostics.Process[] pro=System.Diagnostics.Process.GetProcesses();
foreach(System.Diagnostics.Process pro1 in pro)
{
if(pro1.MainWindowTitle=="计算器")
{
pro1.Kill();
}
}

解决方案 »

  1.   

    System.Diagnostics.Process[] pro=System.Diagnostics.Process.GetProcesses();
    foreach(System.Diagnostics.Process pro1 in pro)
    {
    if(pro1.ProcessName=="calc")
    {
    pro1.Kill();
    }
    }
      

  2.   

    以下是VB.net的代码
    Option Strict Off
    Option Explicit On
    Friend Class Form1
    Inherits System.Windows.Forms.Form
    #Region "Windows 窗体设计器生成的代码"
    Public Sub New()
    MyBase.New()
    If m_vb6FormDefInstance Is Nothing Then
    If m_InitializingDefInstance Then
    m_vb6FormDefInstance = Me
    Else
    Try 
    '对于启动窗体,所创建的第一个实例为默认实例。
    If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
    m_vb6FormDefInstance = Me
    End If
    Catch
    End Try
    End If
    End If
    '此调用是 Windows 窗体设计器所必需的。
    InitializeComponent()
    End Sub
    '窗体重写处置,以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
    If Disposing Then
    If Not components Is Nothing Then
    components.Dispose()
    End If
    End If
    MyBase.Dispose(Disposing)
    End Sub
    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer
    Public ToolTip1 As System.Windows.Forms.ToolTip
    Public WithEvents Command1 As System.Windows.Forms.Button
    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器来修改它。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
    Me.components = New System.ComponentModel.Container()
    Me.ToolTip1 = New System.Windows.Forms.ToolTip(components)
    Me.ToolTip1.Active = True
    Me.Command1 = New System.Windows.Forms.Button
    Me.Text = "Form1"
    Me.ClientSize = New System.Drawing.Size(312, 213)
    Me.Location = New System.Drawing.Point(4, 23)
    Me.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation
    Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
    Me.BackColor = System.Drawing.SystemColors.Control
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable
    Me.ControlBox = True
    Me.Enabled = True
    Me.KeyPreview = False
    Me.MaximizeBox = True
    Me.MinimizeBox = True
    Me.Cursor = System.Windows.Forms.Cursors.Default
    Me.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.ShowInTaskbar = True
    Me.HelpButton = False
    Me.WindowState = System.Windows.Forms.FormWindowState.Normal
    Me.Name = "Form1"
    Me.Command1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    Me.Command1.Text = "Command1"
    Me.Command1.Size = New System.Drawing.Size(81, 33)
    Me.Command1.Location = New System.Drawing.Point(120, 88)
    Me.Command1.TabIndex = 0
    Me.Command1.BackColor = System.Drawing.SystemColors.Control
    Me.Command1.CausesValidation = True
    Me.Command1.Enabled = True
    Me.Command1.ForeColor = System.Drawing.SystemColors.ControlText
    Me.Command1.Cursor = System.Windows.Forms.Cursors.Default
    Me.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.Command1.TabStop = True
    Me.Command1.Name = "Command1"
    Me.Controls.Add(Command1)
    End Sub
    #End Region 
    #Region "升级支持"
    Private Shared m_vb6FormDefInstance As Form1
    Private Shared m_InitializingDefInstance As Boolean
    Public Shared Property DefInstance() As Form1
    Get
    If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
    m_InitializingDefInstance = True
    m_vb6FormDefInstance = New Form1()
    m_InitializingDefInstance = False
    End If
    DefInstance = m_vb6FormDefInstance
    End Get
    Set
    m_vb6FormDefInstance = Value
    End Set
    End Property
    #End Region 
    Private Const WM_CLOSE As Short = &H10s
    Private Declare Function FindWindow Lib "user32"  Alias "FindWindowA"(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Private Declare Function PostMessage Lib "user32"  Alias "PostMessageA"(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

    Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
    TerminateTask("计算器")
    End Sub

    Public Sub TerminateTask(ByVal app_name As String)
    Dim app_hwnd As Integer
    app_hwnd = FindWindow(vbNullString, app_name)
    PostMessage(app_hwnd, WM_CLOSE, 0, 0)
    End Sub
    End Class
      

  3.   

    private void killApp()
    {
      获得进程列表;
     比较你想关闭的进程名在不在列表中;
     如果(在)
      {
       杀掉那个进程;
       }
     如果不在
      {
         给出提示;
      }
    }
    具体怎么杀,上面的老兄们说的已经很清楚了。