我需要有关 .bat 文件代码的帮助,该代码应执行以下操作:
- 退出 Cisco Jabber 应用程序。
从以下位置删除文件和文件夹:
%userprofile%\AppData\Roaming\Cisco\Unified Communications\Jabber
%userprofile%\AppData\Local\Cisco\Unified Communications\Jabber
%userprofile%\AppData\Local\Temp
重置 IE
刷新 DNS 缓存。
下面是我从该论坛找到的示例代码。
@ECHO OFF
SET THEDIR0=C:\Users\lashley\AppData\Local\Temp\
Echo Deleting all files from %THEDIR0% DEL "%THEDIR0%\*" /F /Q /A
Echo Deleting all folders from %THEDIR0% FOR /F "eol=| delims=" %%I in ('dir "%THEDIR0%\*" /AD /B 2^>nul') do rd /Q /S "%THEDIR0%\%%I" @ECHO Folder deleted.
SET THEDIR1=C:\Users\saiku\Desktop\New folder\New folder\
Echo Deleting all files from %THEDIR1% DEL "%THEDIR1%\*" /F /Q /A
Echo Deleting all folders from %THEDIR1% FOR /F "eol=| delims=" %%I in ('dir "%THEDIR1%\*" /AD /B 2^>nul') do rd /Q /S "%THEDIR1%\%%I" @ECHO Folder deleted.
SET THEDIR2=C:\Users\saiku\Desktop\New folder\New folders\
Echo Deleting all files from %THEDIR2% DEL "%THEDIR2%\*" /F /Q /A
Echo Deleting all folders from %THEDIR2% FOR /F "eol=| delims=" %%I in ('dir "%THEDIR2%\*" /AD /B 2^>nul') do rd /Q /S "%THEDIR2%\%%I" @ECHO Folder deleted.
EXIT
注意:我必须以管理员身份手动运行此 .bat 文件才能使其正常工作。是否可以修改此代码,使其只需单击一下即可工作?
注2:我希望此代码可以在任何计算机上运行,无论计算机名称或计算机的用户帐户如何:
示例:
%userprofile%\AppData\Roaming\Cisco\Unified Communications
在这种情况下,我希望删除“统一通信”文件夹
答案1
检查代码中标有“REM”的注释:
@ECHO OFF
REM *Exit Cisco Jabber application.*
REM *Replace "notepad.exe" with the filename of the Jabber application*
SET processname=notepad.exe
tasklist | find /i %processname% && taskkill /im notepad.exe /F || echo process %processname% not running.
REM *Delete files*
REM *I think you have it to run as administrator because you want to access the TEMP folder.*
REM *As a work around you could change the access rights of this folder for all local users. Consider the security issues with this*
SET THEDIR0=%temp%
Echo Deleting all files from %THEDIR0% DEL "%THEDIR0%\*" /F /Q /A
Echo Deleting all folders from %THEDIR0% FOR /F "eol=| delims=" %%I in ('dir "%THEDIR0%\*" /AD /B 2^>nul') do rd /Q /S "%THEDIR0%\%%I" @ECHO Folder deleted.
SET THEDIR1=%userprofile%\Desktop\New folder\New folder\
Echo Deleting all files from %THEDIR1% DEL "%THEDIR1%\*" /F /Q /A
Echo Deleting all folders from %THEDIR1% FOR /F "eol=| delims=" %%I in ('dir "%THEDIR1%\*" /AD /B 2^>nul') do rd /Q /S "%THEDIR1%\%%I" @ECHO Folder deleted.
SET THEDIR2=%userprofile%\Desktop\New folder\New folders\
Echo Deleting all files from %THEDIR2% DEL "%THEDIR2%\*" /F /Q /A
Echo Deleting all folders from %THEDIR2% FOR /F "eol=| delims=" %%I in ('dir "%THEDIR2%\*" /AD /B 2^>nul') do rd /Q /S "%THEDIR2%\%%I" @ECHO Folder deleted.
REM Reset IE
REM What do you mean with this exactly?
REM Do you want to reload a webpage or would restart the browser be enought?
REM Flush DNS
ipconfig /flushdns
EXIT
答案2
@Echo off & CD/d "%~dp0"
Set "_dir=Roaming,Local"
Echo\Killing iE and Jabber!...
Setlocal EnableDelayedExpansion
%:^(
For %%i in ("CiscoJabber.exe", "CiscoJabberPrt.exe",iexplore.exe
)do Rem./ & 2>nul >nul "%__APPDIR__%Taskkill.exe" /f /t /im %%~I
;Echo\Checking if still running... && for %%i in (CiscoJabber,iExplore
)do 2>nul "%__APPDIR__%Tasklist.exe" /nh |Find/i "%%i.exe" >nul && Goto %:^(
>nul 2>&1 "%__APPDIR__%RunDll32.exe" InetCpl.cpl,ClearMyTracksByProcess 4351
%:^)
(%__APPDIR__%Tasklist.exe |Find/i "CiscoJabber.exe" >nul || For %%i in (!_dir!)do (
If /i exist "%UserProfile%\AppData\%%~i\Cisco\Unified Communications\Jabber\*" (
CD /d "%UserProfile%\AppData\%%~i\Cisco\Unified Communications\Jabber\" && (
cmd/v/c "Echo\Deleting: !cd! & RMdir/q/s "!cd!." & Echo\\Deleted: !cd!\" )))
) 2>nul & "%__APPDIR__%Tasklist.exe" |Find/i "CiscoJabber" >nul && Goto %:^(
;Rem./ && Echo\Deleting: %tmp% & 2>nul RMDir/q /s "%tmp%\." & Echo\\Deleted: %tmp%\
;Rem./ && "%__APPDIR__%IPConfig.exe" /flushdns|Find/i "DNS" & Endlocal && Goto=:EOF
- 输出:
Killing iE and Jabber!...
Checking if still running...
Deleting: C:\Users\ecker\AppData\Roaming\Cisco\Unified Communications\Jabber
\Deleted: C:\Users\ecker\AppData\Roaming\Cisco\Unified Communications\Jabber\
Deleting: C:\Users\ecker\AppData\Local\Cisco\Unified Communications\Jabber
\Deleted: C:\Users\ecker\AppData\Local\Cisco\Unified Communications\Jabber\
Deleting: C:\Users\ecker\AppData\Local\Temp
\Deleted: C:\Users\ecker\AppData\Local\Temp\
Successfully flushed the DNS Resolver Cache.
观察:2使用循环的建议for
,以防您需要多个 iE 命令来重置/清理/删除:
For %%i in ( 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 4351, 8192
)do 2>nul >nul "%__APPDIR__%RunDll32.exe" InetCpl.cpl,ClearMyTracksByProcess %%i
1 == Browsing History
2 == Cookies
4 == Temporary Internet Files
8 == Offline favorites and download history
16 == Form Data
32 == Passwords
64 == Phishing Filter Data
128 == Web page Recovery Data
256 == Do not Show GUI when running the cache clear
512 == Do not use Multi-threading for deletion
1024 == Valid only when browser is in private browsing mode
2048 == Tracking Data
4096 == Data stored by add-ons
4351 == Delete all w/Data stored by add-ons
8192 == Preserves Cached data for Favorite websites
- 具有相同输出的替代方案(传统/稍微简单)是:
@Echo off
CD /d "%~dp0"
Setlocal EnableDelayedExpansion
:to_kill_process
For %%i in (CiscoJabber.exe,CiscoJabberPrt.exe,iexplore.exe)do (
"%__APPDIR__%Taskkill.exe" /f /t /im %%~i
) 2>nul >nul
Echo\Stop/Kill iE and/or CiscoJabber... & echo\
For %%i in (CiscoJabber.exe,CiscoJabberPrt.exe,iexplore.exe)do (
"%__APPDIR__%tasklist.exe" /nh |Find/i "%%i.exe"
) 2>nul >nul&& Goto :to_kill_process
<con: Set /p "=Resetting iExplorer." <nul && (
"%__APPDIR__%RunDll32.exe" InetCpl.cpl,ClearMyTracksByProcess 4351
) && echo\ is Done..
echo\..done!
:to_del_folders
(
%__APPDIR__%Tasklist.exe |Find/i "CiscoJabber.exe" >nul
) || (
For %%i in (!_dir!) do If /i exist "%UserProfile%\AppData\%%~i\Cisco\Unified Communications\Jabber\*" (
(
CD /d "%UserProfile%\AppData\%%~i\Cisco\Unified Communications\Jabber\"
) && (
Echo\ & cmd.exe /v:on /c "Echo\Deleting: !cd! & RMdir /q /s "!cd!." & Echo\\Deleted: !cd!\"
)
)
) 2>nul
"%__APPDIR__%tasklist.exe" | Find/i "CiscoJabber" >nul && Goto :to_kill_process
Echo\ & Echo\Deleting: %tmp%
2>nul RMDir/q /s "%tmp%\."
Echo\\Deleted: %tmp%\ & Echo/
<con: Set /p "=Cleaning up DNsServerCache: " <nul
"%__APPDIR__%ipconfig.exe" /flushdns |find/i "DNS"
Endlocal & Goto :EOF
- 输出:
Stop/Kill iE and/or CiscoJabber...
Resetting iExplorer...done
Deleting: C:\Users\ecker\AppData\Roaming\Cisco\Unified Communications\Jabber
\Deleted: C:\Users\ecker\AppData\Roaming\Cisco\Unified Communications\Jabber\
Deleting: C:\Users\ecker\AppData\Local\Cisco\Unified Communications\Jabber
\Deleted: C:\Users\ecker\AppData\Local\Cisco\Unified Communications\Jabber\
Deleting: C:\Users\ecker\AppData\Local\Temp
\Deleted: C:\Users\ecker\AppData\Local\Temp\
Cleaning up DNsServerCache: Successfully flushed the DNS Resolver Cache.