我正在尝试清理所有用户配置文件。我写了一个批处理文件,它会在登录用户运行时删除所有文件/目录。但是,我们希望在周末没有登录时让所有用户都参与此活动。我不熟悉Vb Script以及一般编码。解决这个问题的不同想法是运行我们所有用户配置文件的循环,这些配置文件会将找到的每个用户名写入数组。然后让批处理文件调用数组中的每个名称,然后运行删除过程。但就像我说的那样,我对阵列和环回来说是非常新的和缺乏经验的。
这是我写的批处理文件:
MOVE "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\Extensions" "C:\Users\%username%\AppData\Local\Google\Chrome\"
MOVE "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\Bookmarks" "C:\Users\%username%\AppData\Local\Google\Chrome"
Move "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\Bookmarks.bak" "C:\Users\%username%\AppData\Local\Google\Chrome"
Move "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\Preferences" "C:\Users\%username%\AppData\Local\Google\Chrome"
Move "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\History-journal" "C:\Users\%username%\AppData\Local\Google\Chrome"
Move "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\History" "C:\Users\%username%\AppData\Local\Google\Chrome"
del /S /Q "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\*"
MOVE "C:\Users\%username%\AppData\Local\Google\Chrome\Bookmarks" "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\"
MOVE "C:\Users\%username%\AppData\Local\Google\Chrome\Bookmarks.bak" "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\"
MOVE "C:\Users\%username%\AppData\Local\Google\Chrome\Preferences" "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\"
MOVE "C:\Users\%username%\AppData\Local\Google\Chrome\Extensions" "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\"
MOVE "C:\Users\%username%\AppData\Local\Google\Chrome\History-journal" "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\"
MOVE "C:\Users\%username%\AppData\Local\Google\Chrome\History" "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\"
我假设必须修改%username%而不是从数组调用。 您将对该过程的任何部分提供任何帮助,我们将不胜感激。 谢谢。
答案 0 :(得分:0)
编辑:现在我知道你想要什么了
我将所有%username%
更改为%%a
,因为我们逐行从 ALL_USERNAME_ARE_STORED_HERE.txt 获取用户名。
@Echo off
Setlocal EnableDelayedExpansion
for /f "tokens=*" %%a in (ALL_USERNAME_ARE_STORED_HERE.txt) do (
MOVE "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\Default\Extensions" "C:\Users\%%a\AppData\Local\Google\Chrome\"
MOVE "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\Default\Bookmarks" "C:\Users\%%a\AppData\Local\Google\Chrome"
Move "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\Default\Bookmarks.bak" "C:\Users\%%a\AppData\Local\Google\Chrome"
Move "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\Default\Preferences" "C:\Users\%%a\AppData\Local\Google\Chrome"
Move "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\Default\History-journal" "C:\Users\%%a\AppData\Local\Google\Chrome"
Move "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\Default\History" "C:\Users\%%a\AppData\Local\Google\Chrome"
del /S /Q "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\*"
MOVE "C:\Users\%%a\AppData\Local\Google\Chrome\Bookmarks" "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\Default\"
MOVE "C:\Users\%%a\AppData\Local\Google\Chrome\Bookmarks.bak" "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\Default\"
MOVE "C:\Users\%%a\AppData\Local\Google\Chrome\Preferences" "C:\Users\%%aAppData\Local\Google\Chrome\User Data\Default\"
MOVE "C:\Users\%%a\AppData\Local\Google\Chrome\Extensions" "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\Default\"
MOVE "C:\Users\%%a\AppData\Local\Google\Chrome\History-journal" "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\Default\"
MOVE "C:\Users\%%a\AppData\Local\Google\Chrome\History" "C:\Users\%%a\AppData\Local\Google\Chrome\User Data\Default\"
)
pause >nul
如果我再次误解你,请告诉我。
*仔细检查所有%username%
是否已更改为%%a
。