用VBA来关闭其他程序

以关闭Winrar.exe为例,代码如下:

 

Sub closeWinrar()
    Dim oWMT As Object, oProcess As Object
    Set oWMT = GetObject("winmgmts://")
    For Each oProcess In oWMT.InstancesOf("Win32_Process")
        If LCase(oProcess.Name) = "winrar.exe" Then
            If oProcess.Terminate() = 0 Then Exit Sub
        End If
    Next
End Sub

 

 

posted @ 2010-07-13 20:12  RobinLao  阅读(2115)  评论(0编辑  收藏  举报