2014-10-31 66 views
0

我远程进入计算机并放入几个文件以修复计算机。我有一个批处理文件,可以停止除批处理文件中包含的所有正在运行的程序。批处理文件 - 除列出的服务外,正在停止服务

我想另一个去,虽然每个服务并停止它除了在批处理文件的几个制作虚拟安全模式。如果它没有运行,我希望它跳过该服务。 (并回显是否运行) 我将不得不运行几次来停止依赖关系,但我会根据需要手动执行此操作。我有一个类似的程序,它使用外部文本文件服务来保持运行,但希望使用包含在批处理文件中的服务的单个文件代码如下。

任何人都可以为我抓这个吗?对此,我真的非常感激!

(Thanks to Bharat) 
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" 
echo. 
) 
) 
) 
) 
) 
+0

首先,你到目前为止尝试过什么?其次,你有没有使用PowerShell的原因?这样**会更容易**。 – briantist 2014-10-31 01:06:53

回答

0

我完成了我的脚本,有更多的研究。我知道它很丑,但它允许我在远程计算机上运行,​​还有增长空间。它有一个内置的忽略列表,删除临时文件并打开文件夹以确认所有其他区域都是空的。 为什么不使用powershell?我对Windows命令的了解不多。只是想分享并获得改善。

@echo off 
title Kill all running apps 
color 0A 
:start 

cd c:\windows\System32 
for /f "skip=3 tokens=1" %%i in ('TASKLIST /FI "USERNAME eq    %userdomain%\%username%" /FI "STATUS eq running"') do (
echo %%i 
if not "%%i"=="svchost.exe" (
if not "%%i"=="explorer.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="tasklist.exe" (
if not "%%i"=="notepad.exe" (
if not "%%i"=="dllhost.exe" (
if not "%%i"=="cis.exe" (
if not "%%i"=="cistray.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="taskmgr.exe" (
if not "%%i"=="conhost.exe" (
::desktop windows manager 
if not "%%i"=="dwm.exe" (
if not "%%i"=="tv_w32.exe" (
if not "%%i"=="tv_x64.exe" (
if not "%%i"=="TeamViewer.exe" (
if not "%%i"=="taskmgr.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="cmd.exe" (
if not "%%i"=="cmd.exe" (
echo. 
echo %%i 
ping -n 2 -w 1 127.0.0.1>nul 
taskkill /f /im "%%i" 
ping -n 2 -w 1 127.0.0.1>nul 
echo. 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 

:open 
explorer.exe "%USERPROFILE%\AppData\Local\Microsoft\Windows\Temporary  Internet Files\" 
explorer.exe "%USERPROFILE%\AppData\Local\Temp\" 
explorer.exe %windir%\temp 

:delete 
echo.&echo.&Echo Now empty temp files. 
::=========Delete temp files========= 
::empty user temp folder 
cd /d %temp% 
echo.&echo.&echo deleting files....... 
for /d %%D in (*) do rd /s /q "%%D" 
del /f /q * 

::empty Admin temp folder 


echo.&echo.&echo Empty windows temp file 
cd /d %windir%\temp\ 
::dir /w 
echo.&echo.&echo deleting files....... 
for /d %%D in (*) do rd /s /q "%%D" 
del /f /q * 

goto folders 


:folders 
echo Now turn off processes 
taskmgr 
msconfig 
Taskschd.msc 
ping -n 5 -w 1 127.0.0.1>nul 

:eof