【问题标题】:Batch script to Delete an IE 11 File删除 IE 11 文件的批处理脚本
【发布时间】:2015-01-26 23:15:38
【问题描述】:

我写这篇文章是出于无聊,但我需要一点帮助。下面的代码是完整的,但我会将它分成更小的块,因为选项 2 很痛苦。

@echo off
Set SQMFile="C$\Users\Default\AppData\Local\Microsoft\Windows\Temporary Internet Files\SQM"
Set CSVFile="%userprofile\Documents"
:top
cls
echo.
echo You upgraded to IE 11 and now you can't login
echo follow the prompts below and I will fix it 
echo for you :)
echo.
echo.
echo 1) Single Computer? 
echo 2) Multiple Computers? (txt file)
echo 3) Help menu
echo. 
echo.
Set /p C="What do you want to do? "
if %C%==1 goto opt1
if %C%==2 goto opt2
if /i %C%==3 goto help
::===================================================================
:opt1
Set /p comname="Whats the computer name? "
if exist "\\%comname%\%SQMFile\iesqmdata_setup0.sqm" (
    echo File is there...
    echo Deleting File
    del "\\%comname%\%SQMFile\iesqmdata_setup0.sqm" 
    goto top
) else (
    echo File is not there
    goto top
)
::===================================================================
:opt2
Set /p opt2="Is the file in your Documents folder named Computers.txt? (Y/N) "
if /i %opt2%==y goto file
if /i %opt2%==n goto loc
::===================================================================
:loc
cls
echo Where's the file located and what's it called?
echo example "C:\users\<username>\documents\list of comptures.txt"
set /p newloc="No need for quotes: "
echo In File label
pause
for /F %%G in ("%newloc%") DO (
    if exist "\\%%G\%SQMFile\iesqmdata_setup0.sqm" (
    echo File is there
    pause
    ::del "\\%%G\%SQMFile\iesqmdata_setup0.sqm"
    ) else ( 
    echo File is not there
    )
)
Pause
goto top
::===================================================================
:file
echo In File label
pause
for /F %%G in ("%CSVFile%\Computers.txt") DO (
    if exist "\\%%G\%SQMFile\iesqmdata_setup0.sqm" (
    echo File is there
    ::del "\\%%G\%SQMFile\iesqmdata_setup0.sqm"
    ) else ( 
    echo File is not there
    )
)
Pause
goto top
::===================================================================
:help
cls
echo.
echo.
echo =================Help Menu===========================
echo This script is used only for deleting the .sqm
echo file that likes to break the "User Logon Service"
echo for computers after updating to IE 11
echo.
echo Option 1 is for single computers.
echo It checks for the file and if there it
echo deletes it.
echo.
echo Option 2 does the same as 1 but is more geared towards 
echo mass amounts of computers. a multi line, single entry
echo file is supported ex:Line1
echo                 Line2
echo                 Line3
echo Please save the file in %userprofile%\Documents
echo with the file name Computers.txt
echo =====================================================
echo.
echo.
Pause 
goto top

:eof

正如我在上面所说的那样,选项 2 给我 ") was unexpected at this time" 是和否。

:loc

一直工作到For /F,这就是决定失败并抛出错误的地方。 但我要做的是读取名称文件并检查文件是否存在删除它。如果没有,则循环到下一个。

有问题的块:

:opt2
Set /p opt2="Is the file in your Documents folder named Computers.txt? (Y/N) "
if /i %opt2%==y goto file
if /i %opt2%==n goto loc
::===================================================================
:loc
cls
echo Where's the file located and what's it called?
echo example "C:\users\<username>\documents\list of comptures.txt"
set /p newloc="No need for quotes: "
echo In File label
pause
for /F %%G in ("%newloc%") DO (
    if exist "\\%%G\%SQMFile\iesqmdata_setup0.sqm" (
    echo File is there
    pause
    ::del "\\%%G\%SQMFile\iesqmdata_setup0.sqm"
    ) else ( 
    echo File is not there
    )
)
Pause
goto top
::===================================================================
:file
echo In File label
pause
for /F %%G in ("%CSVFile%\Computers.txt") DO (
    if exist "\\%%G\%SQMFile\iesqmdata_setup0.sqm" (
    echo File is there
    ::del "\\%%G\%SQMFile\iesqmdata_setup0.sqm"
    ) else ( 
    echo File is not there
    )
)
Pause
goto top

【问题讨论】:

  • 这可能是您尝试使用:: 作为括号代码块中的注释标记。您必须使用 rem 来表示代码块中的 cmets。如果您愿意,请使用rem ::,但尽管如此,请使用rem。严格来说,大多数时候当您看到:: 表示批处理脚本中的注释时,它实际上只是一个未使用的标签。但是,如果您尝试在括号中的代码块中粘贴标签,则会出现错误。
  • 全部更改。我不知道:: 不好。谢谢

标签: batch-file if-statement for-loop cmd


【解决方案1】:

if exist "\\%%G\%SQMFile\iesqmdata_setup0.sqm" ((以及更多)中缺少%。应该是

if exist "\\%%G\%SQMFile%\iesqmdata_setup0.sqm" (

并摆脱结束:eof标签...这是一个预定义标签,它将退出当前例程。要退出批处理脚本文件或退出子程序,请指定GOTO :eof,这会将控制权转移到当前批处理文件的结尾或当前子程序的结尾。

编辑:

Set "SQMFile=C$\Users\Default\AppData\Local\Microsoft\Windows\Temporary Internet Files\SQM"
Set "CSVFile=%userprofile%\Documents"

听从 rojorem 与有害 :: 的建议。

【讨论】:

  • 啊,所以我错过了文件中的一大堆%。把它们都换了,现在她像小猫一样咕噜咕噜叫。谢谢你。如果您愿意,我可以发布完整的文件以备将来 IE 升级失败。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 2012-04-28
  • 1970-01-01
  • 1970-01-01
  • 2018-09-05
相关资源
最近更新 更多