NSN*_*NSN 13 windows windows-shell
如何使用taskkill从名称和特定路径中删除进程?
taskkill/F/IM
当然它无法区分2个过程从两个不同的位置开始C:\ Dir1和C:\ Dir2
任务列表是否有任何开关来获取路径名称
Joe*_*oey 11
taskkill
做不到.但是如果它是一个选项,你可以使用PowerShell:
(Get-WmiObject Win32_Process | Where-Object { $_.Path.StartsWith('C:\Dir1') }).Terminate()
Run Code Online (Sandbox Code Playgroud)
基于乔伊的回答:
wmic Path win32_process Where "CommandLine Like '%C:\\Dir1\\image.exe%'" Call Terminate
Run Code Online (Sandbox Code Playgroud)
这样,当 Path 为空(不知道为什么)并且不需要 PowerShell 时,我可以避免 NullReferenceException。
参考:https : //superuser.com/questions/52159/kill-a-process-with-a-specific-command-line-from-command-line
警告
如果使用命令行运行的其他进程包含该图像路径,则很危险。例如:
> start cmd /k "C:\windows\system32\notepad.exe"
> wmic Path win32_process where "CommandLine Like '%C:\\Windows\\system32\\notepad.exe%'" get caption,processid,executablePath,commandline
Caption CommandLine ExecutablePath ProcessId
cmd.exe cmd /k "C:\windows\system32\notepad.exe" C:\WINDOWS\system32\cmd.exe 11384
notepad.exe C:\windows\system32\notepad.exe C:\windows\system32\notepad.exe 9684
Run Code Online (Sandbox Code Playgroud)
那么...如果我们使用“C:\Dir1\image.exe%”而不是“%C:\Dir1\image.exe%”会怎样?
如果我们从资源管理器启动这个程序,它的命令行可能会被引用。如果我们忽略它,将没有匹配项:
> wmic Path win32_process where "CommandLine Like '%C:\\Windows\\system32\\notepad.exe%'" get caption,processid,executablePath,commandline
Caption CommandLine ExecutablePath ProcessId
notepad.exe "C:\WINDOWS\system32\notepad.exe" C:\WINDOWS\system32\notepad.exe 108
> wmic Path win32_process where "CommandLine Like 'C:\\Windows\\system32\\notepad.exe%'" get caption,processid,executablePath,commandline
No Instance(s) Available.
Run Code Online (Sandbox Code Playgroud)
因此,建议使用“ExecutablePath”,如 l0pan 的回答。
使用以下命令(即使没有 powershell 也能工作):
wmic process where ExecutablePath='C:\\Dir1\\image.exe' delete
Run Code Online (Sandbox Code Playgroud)
注意:仅当您wmic
在 Windows 8 上以管理员身份运行时,所有进程都可以访问 ExecutablePath
归档时间: |
|
查看次数: |
7170 次 |
最近记录: |