- 帖子
- 155
- 主題
- 1
- 精華
- 0
- 積分
- 200
- 點名
- 4
- 作業系統
- windwos 7
- 軟體版本
- 64bit
- 閱讀權限
- 20
- 註冊時間
- 2017-5-29
- 最後登錄
- 2026-10-25
|
本帖最後由 quickfixer 於 2018-8-17 01:50 編輯
試看看
Sub stopApp()
Dim app As String
Dim objWMI As Object, objProcess As Object, objList As Object
Dim intError As Integer
app = "calc.exe" '這裡填入要關閉的執行檔名稱
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objList = objWMI.ExecQuery("select * from win32_process where name='" & app & "'")
For Each objProcess In objList
intError = objProcess.Terminate
If intError <> 0 Then Exit For
Next
Set objWMI = Nothing
Set objList = Nothing
Set objProcess = Nothing
End Sub |
|