我想用vbs结束cmd.exe这个进程,所以就不能调用cmd命令。求代码和解析

2024-12-05 16:09:25
推荐回答(1个)
回答1:

方法一:
Set WMI=GetObject("winmgmts:\\.\root\cimv2")
Set ProgList=WMI.ExecQuery("Select * From Win32_Process")
For Each Prog In ProgList
If LCase(Prog.Name)="cmd.exe" Then
Prog.Terminate
Exit For
End If
Next

方法二:
Set WshShell=CreateObject("Wscript.Shell")
Set WMI=GetObject("winmgmts:\\.\root\cimv2")
Set ProgList=WMI.ExecQuery("Select * From Win32_Process")
For Each Prog In ProgList
If LCase(Prog.Name)="cmd.exe" Then
wshshell.Run "cmd /c ntsd -c q -p "+Prog.ProcessID,0
Exit For
End If
Next
P.S. ntsd 可以结束任何进程(除了系统关键进程)