我是一个初学者,我只是对cmd感到好奇,所以我想做一个批处理文件来杀死活动的窗口,并安全地关闭/重新启动计算机。我遇到了像这样的命令-
taskkill /im "program.exe“
任务列表
关闭-s
但我想关闭所有活动窗口,但不是强制关闭。如果有一个特定的命令或一些命令的组合,请务必说明。提前谢谢。
PS-我遇到了powershell,但我想知道是否可以使用批处理文件(cmd命令)来实现这一点,链接是.Below
发布于 2019-07-08 16:37:50
如果您在explorer.exe上执行treekill,它将关闭除后台进程之外的所有其他程序。这些批处理脚本只有在以使其成为后台进程、系统进程或不是explorer.exe的子进程的异常方式被调用时才会起作用。
下面是我的treekill浏览器方法最快的参考实现
@echo off
echo closing all programs...
taskkill /f /t /im explorer.exe
explorer.exe下面是我的treekill explorer方法与hibernate相结合的示例实现,以创建一个快速关机和启动脚本。
@echo off
echo shutting down...
echo closing all programs...
taskkill /f /t /im explorer.exe
echo hibernating...
shutdown /f /h
echo restoring...
explorer.exe
echo thanks you for using JessieTessie's fast shutdown and startup.发布于 2019-01-21 21:25:40
title Kill all running apps
cd c:\windows\System32
for /f "skip=3 tokens=1" %%i in ('TASKLIST /FI "USERNAME eq %userdomain%\%username%" /FI "STATUS eq running"') do (
if not "%%i"=="svchost.exe" (
if not "%%i"=="explorer.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="tasklist.exe" (
echo.
taskkill /f /im "%%i"
taskkill /f /im explorer.exe
echo.
)
)
)
)
)
pause发布于 2021-04-15 14:02:20
你可以做到
@echo off
@powershell Get-Process | Where-Object {$_.MainWindowTitle -ne ""} | stop-process
taskkill /f /im explorer.exe它将执行powershell命令,该命令将查找并关闭所有未使用windowtitle隐藏或释放的运行程序。但它将关闭所有应用程序,包括您的应用程序。为了防止出现这种情况,您需要从c++重新编码(您可以在windows.h中使用system("somecommand") ),并且在执行closeAll命令之前将freeconsole()放入代码中。但是你需要找到如何找回控制台的方法。
https://stackoverflow.com/questions/38750905
复制相似问题