目前了解到的可以编程通过进程名关闭一些进程,但还可以改变程序名称啊,程序就关不了啦,高手办忙,谢啦!

解决方案 »

  1.   

    多谢,我网上查拉半天,写拉以下代码。请帮忙参详以下
    '*********************************************************
    ' 目    的: 关闭进程
    ' 参数说明:
    '
    ' 日    期:     BY      COMMENT    CONTENT
    ' ----------    ----    -------    -------
    ' 2005/04/09        Jian      建立
    '*********************************************************
    Public Function CloseProcs(Proc As Long)
      Dim i As Long
      Dim hand As Long
      hand = OpenProcess(PROCESS_TERMINATE, True, Proc)  '注释:获取进程控制码
      TerminateProcess hand, 0 '注释:关闭进程
      CloseHandle (Proc)
    End Function
    '*********************************************************
    ' 目    的: 检查打开的窗体
    ' 参数说明:
    '
    ' 日    期:     BY      COMMENT    CONTENT
    ' ----------    ----    -------    -------
    ' 2005/04/09        Jian      建立
    '*********************************************************
    Public Function InspectWindows()
    Dim RenHWND As Long
    Dim retvalue As Long
    Dim WinTextLength As Long
    Dim GetPro As Long
    Dim proceID As Long
    RenHWND = GetWindow(frmAllSystem.hwnd, GW_HWNDFIRST)
    Do
    retvalue = GetWindowText(RenHWND, WinText, 256)
    If retvalue <> 0 Then
    If Left$(WinText, WinTextLength) <> frmAllSystem.Caption And Left$(WinText, WinTextLength) <> App.Title Then
      If InStr(1, WinText, "QQ") <> 0 Then
          GetPro = GetWindowThreadProcessId(RenHWND, proceID)
          CloseProcs proceID
      End If
     
    End If
    End If
    RenHWND = GetWindow(RenHWND, GW_HWNDNEXT)
    Loop Until RenHWND = 0
    Call CloseHandle(RenHWND)
    Call CloseHandle(retvalue)
    Call CloseHandle(GetPro)
     End Function
    Private Sub Ttimer_Timer()
     
    InspectWindows
    End Sub
    问题是,运行不稳定,有时造成程序退出,包括后台运行的防毒,msn,或者输入法的图标消失,
      

  2.   

    关机和重新启动Windows
    Shell "rundll.exe user.exe,exitwindowsexec", vbHide '重新启动
    Shell "rundll.exe user.exe,exitwindows", vbHide '关闭
      

  3.   

    我写的是查QQ窗体,发现啦就把他光闭,,但有时造成程序退出,包括后台运行的防毒,msn,或者输入法的图标消失,请帮帮!
    '模
    '*********************************************************
    ' 目    的: 關閉進程
    ' 參數說明:
    '
    ' 日    期:     BY      COMMENT    CONTENT
    ' ----------    ----    -------    -------
    ' 2005/04/09        Jian      建立
    '*********************************************************
    Public Function CloseProcs(Proc As Long)
      Dim I As Long
      Dim hand As Long
      hand = OpenProcess(PROCESS_TERMINATE, True, Proc)  '注釋:獲取進程控制碼
      TerminateProcess hand, 0 '注釋:關閉進程
      CloseHandle (Proc)
    End Function
    '*********************************************************
    ' 目    的: 檢查打開的窗體
    ' 參數說明:
    '
    ' 日    期:     BY      COMMENT    CONTENT
    ' ----------    ----    -------    -------
    ' 2005/04/09        Jian      建立
    '*********************************************************
    Public Function InspectWindows()
    Dim RenHWND As Long
    Dim retvalue As Long
    Dim WinTextLength As Long
    Dim GetPro As Long
    Dim proceID As Long
    RenHWND = GetWindow(frmAllSystem.hWnd, GW_HWNDFIRST) '獲取第一個窗體句柄
    Do
    retvalue = GetWindowText(RenHWND, WinText, 256) '獲取窗體標題
    'WinTextLength = GetWindowTextLength(RenHWND)
    If retvalue <> 0 Then
       If InStr(1, WinText, "QQ") <> 0 Then
          GetPro = GetWindowThreadProcessId(RenHWND, proceID)  '
          CloseProcs proceID
      End If
     
     
    End If
    RenHWND = GetWindow(RenHWND, GW_HWNDNEXT)
    Loop Until RenHWND = 0
    Call CloseHandle(RenHWND)
    Call CloseHandle(retvalue)
    Call CloseHandle(GetPro)
     End Function
    '窗
    Private Sub Ttimer_Timer()
     InspectWindows
    End Sub
      

  4.   

    稍微改了一下,试着没发现问题
    Option Explicit
    Dim WinText As String * 256
    Const GW_HWNDFIRST = 0
    Const GW_HWNDNEXT = 2
    Const PROCESS_TERMINATE As Long = &H1
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    '*********************************************************
    ' 目    的: 關閉進程
    ' 參數說明:
    '
    ' 日    期:     BY      COMMENT    CONTENT
    ' ----------    ----    -------    -------
    ' 2005/04/09        Jian      建立
    '*********************************************************
    Public Function CloseProcs(Proc As Long)
      Dim I As Long
      Dim hand As Long
      hand = OpenProcess(PROCESS_TERMINATE, True, Proc)  '注釋:獲取進程控制碼
      TerminateProcess hand, 0 '注釋:關閉進程
      'CloseHandle (Proc)
    End Function
    '*********************************************************
    ' 目    的: 檢查打開的窗體
    ' 參數說明:
    '
    ' 日    期:     BY      COMMENT    CONTENT
    ' ----------    ----    -------    -------
    ' 2005/04/09        Jian      建立
    '*********************************************************
    Public Function InspectWindows()
    Dim RenHWND As Long
    Dim retvalue As Long
    Dim WinTextLength As Long
    Dim GetPro As Long
    Dim proceID As Long
    RenHWND = GetWindow(frmAllSystem.hwnd, GW_HWNDFIRST) '獲取第一個窗體句柄
    Do
    retvalue = GetWindowText(RenHWND, WinText, 256) '獲取窗體標題
    'WinTextLength = GetWindowTextLength(RenHWND)
    If retvalue <> 0 Then
       If InStr(1, WinText, "QQ") <> 0 Then
          GetPro = GetWindowThreadProcessId(RenHWND, proceID)  '
          CloseProcs proceID
      End If
     
     
    End If
    RenHWND = GetWindow(RenHWND, GW_HWNDNEXT)
    Loop Until RenHWND = 0
    'Call CloseHandle(RenHWND)
    'Call CloseHandle(retvalue)
    'Call CloseHandle(GetPro)
     End Function
    '窗
    Private Sub Ttimer_Timer()
     InspectWindows
    End Sub
      

  5.   

    'Call CloseHandle(RenHWND)
    'Call CloseHandle(retvalue)
    'Call CloseHandle(GetPro)
    需要closehandle嗎?
      

  6.   

    retvalue肯定不需要,另外两个也应该不需要,因为它们即使是对象也不是你的程序建立的。