【发布时间】: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