2015-01-26 49 views
0

我写这个是无聊,但我需要一点帮助。下面的代码是整体,但我会分解成更小的块,因为选项2是一个痛苦。批处理脚本删除一个IE 11文件

@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"两个Yes和No.

: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 
+1

可能是因为您正在尝试在括号内的代码块中使用'::'作为注释标记。您必须使用'rem'来表示代码块中的注释。如果你愿意,使用'rem ::',但是'rem'。严格地说,大多数情况下,当你看到'::'表示批处理脚本中的注释时,它实际上只是一个未使用的标签。但是如果您尝试在括号代码块中粘贴标签,则会出错。 – rojo 2015-01-27 00:06:02

+0

改变了他们。我不知道'::'不好。谢谢 – Benny 2015-01-27 15:35:06

回答

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" 

按照第rem对有害::罗霍的建议。

+0

啊,所以我错过了一大堆'%'文件。改变了他们,现在她像小猫一样咕噜咕噜叫。谢谢。如果你想我可以发布完整的文件,以备将来的IE升级失败。 – Benny 2015-01-27 15:36:21

相关问题