如何在批处理文件中添加是/否响应

时间:2018-06-08 14:53:39

标签: batch-file

我有一个脚本,我想在执行每个配置文件删除/删除之前添加是/否响应。此脚本用于删除远程工作站上的旧配置文件。它允许我进入我想要远程的工作站并调用自上次登录配置文件以来的天数。例如,如果我输入自上次登录后60天,将删除过去60天内未登录的所有配置文件。我想在删除个人资料之前选择是或否。该脚本其他方式正常。这是脚本。任何帮助,将不胜感激。提前谢谢!

@ECHO OFF
echo ####################################################
echo #                                                 #
echo #   Welcome to the User Profile Deletion tool,   #
echo #   this tool is to only be used on common use   #
echo #       Computers, to clear old profiles       #
echo #                                                 #
echo #   you will be prompted for approving offical   #
echo #   This is the requestor of the profile wipe!   #
echo #   and the number of days since last logon,   #
echo #         you wish to start the clean at.       # 
echo #                                                 #
echo ####################################################
echo.
REM set /p approving=approving offical that requested the wipe:
set /p days2=How many days to keep? 
echo.
set UsersPath=%systemdrive%\Users\
DEL /F /Q /A:H %UsersPath%\desktop.ini 2>nul>nul
forfiles /p %UsersPath% /m * /d -%days2% /c "cmd /c echo @file">%TEMP%\users.temp
FOR /F "skip=1 tokens=1 delims=" %%P IN (%TEMP%\users.temp) DO CALL:UserDeleteJoin %%P
set userdelete=%userdelete:"=%
set userdelete=%userdelete:~0,-1%
GOTO:USERPRESERVE

:UserDeleteJoin
if UserDeleteJoin_Skip=="" (set userdelete=%1 & set UserDeleteJoin_Skip=1) ELSE (set userdelete=%1,%userdelete%)
goto:eof

:USERPRESERVE
set userpreserve="All Users,Default,Default User,Public,AnyOtherUserName"

FOR /f "tokens=*" %%a IN ('reg query "hklm\software\microsoft\windows nt\currentversion\profilelist"^|find /i "s-1-5-21"') DO CALL :REGCHECK "%%a"
GOTO VERIFY

:REGCHECK
set SPACECHECK=
FOR /f "tokens=3,4" %%b in ('reg query %1 /v ProfileImagePath') DO SET USERREGPATH=%%b %%c
FOR /f "tokens=2" %%d in ('echo %USERREGPATH%') DO SET SPACECHECK=%%d
IF ["%SPACECHECK%"]==[""] GOTO REGCHECK2
GOTO USERCHECK

:REGCHECK2
FOR /f "tokens=3" %%g in ('reg query %1 /v ProfileImagePath') DO SET USERREGPATH=%%g
GOTO USERCHECK

:USERCHECK
FOR /f "tokens=3 delims=\" %%e in ('echo %USERREGPATH%') DO SET USERREG=%%e
FOR /f "tokens=1 delims=." %%f IN ('echo %USERREG%') DO SET USERREGPARSE=%%f
ECHO %USERPRESERVE%|find /I "%USERREGPARSE%" > NUL
IF ERRORLEVEL=1 GOTO DELETECHECK
IF ERRORLEVEL=0 GOTO SKIP

:DELETECHECK
FOR /f "tokens=3 delims=\" %%e in ('echo %USERREGPATH%') DO SET USERREG=%%e
FOR /f "tokens=1 delims=." %%f IN ('echo %USERREG%') DO SET USERREGPARSE=%%f
ECHO %userdelete%|find /I "%USERREGPARSE%" > NUL
IF ERRORLEVEL=1 GOTO SKIP
IF ERRORLEVEL=0 GOTO CLean
GOTO:EOF

:SKIP
ECHO Skipping user clean for %USERREG%
GOTO :EOF

:CLEAN
set /a profiles=%profiles%+1
ECHO Cleaning user profile for %USERREG%
rmdir /s "C:\Users\%USERREG%" /s /q > NUL
ECHO Cleaning user registry for %USERREG%
reg delete %1 /f
IF EXIST "C:\Users\%USERREG%" GOTO RETRYCLEAN1
GOTO :EOF

:RETRYCLEAN1
ECHO Retrying clean of user profile %USERREG%
rmdir /s "C:\Users\%USERREG%" /s /q > NUL
IF EXIST "C:\Users\%USERREG%" GOTO RETRYCLEAN2
GOTO :EOF

:RETRYCLEAN2
ECHO Retrying clean of user profile %USERREG%
rmdir "C:\Users\%USERREG%" /s /q > NUL
GOTO :EOF

:VERIFY
FOR /f "tokens=*" %%g IN ('reg query "hklm\software\microsoft\windows nt\currentversion\profilelist"^|find /i "s-1-5-21"') DO CALL :REGCHECKV "%%g"
GOTO REPORT

:REGCHECKV
set SPACECHECKV=
FOR /f "tokens=3,4" %%h in ('reg query %1 /v ProfileImagePath') DO SET USERREGPATHV=%%h %%i
FOR /f "tokens=2" %%j in ('echo %USERREGPATHV%') DO SET SPACECHECKV=%%j
IF ["%SPACECHECKV%"]==[""] GOTO REGCHECKV2
GOTO USERCHECKV

:REGCHECKV2
FOR /f "tokens=3" %%k in ('reg query %1 /v ProfileImagePath') DO SET USERREGPATHV=%%k
GOTO USERCHECKV

:USERCHECKV
FOR /f "tokens=3 delims=\" %%l in ('echo %USERREGPATHV%') DO SET USERREGV=%%l
FOR /f "tokens=1 delims=." %%m IN ('echo %USERREGV%') DO SET USERREGPARSEV=%%m
ECHO %USERPRESERVE%|find /I "%USERREGPARSEV%" > NUL
IF ERRORLEVEL=1 GOTO VERIFYERROR
IF ERRORLEVEL=0 GOTO :EOF

:VERIFYERROR
SET USERERROR=YES
GOTO :EOF

:REPORT
IF [%USERERROR%]==[YES] (
        set RESULT=FAILURE
)     ELSE (
        set RESULT=SUCCESS
)

echo Total Profiles Cleaned is %profiles%
Pause
:EXIT
exit

:EOF

1 个答案:

答案 0 :(得分:0)

在第66行的第:CLEAN行之后插入这3行。

set "reply=y"
set /p "reply=Clean user profile for %USERREG%? [y|n]: "
if /i not "%reply%" == "y" goto :eof

如果您输入y或只按输入隐含y的输入,则会继续清除,否则其他输入意味着n会转到文件末尾。