我试图自动化我们在本地为每个用户执行的用户配置,这就是为什么我通过批处理文件进行配置的原因。作为其中的一部分,我需要将他们的Documents文件夹重定向到映射为他们U盘的内容。如果我的文档文件夹存在于他们的U盘中,我需要它到达那里,如果没有,我需要将它映射到他们U盘的根目录。本地文件夹重定向到映射网络驱动器批处理文件
下面的代码是我目前有的,但它总是默认为Else条件,即使我有我检查的文件夹。
如果有人可以帮忙,请做。
@echo off
cd\ & cls
set UDRIVE="u:\My Documents\"
If exist %udrive% (set newDocuments=%udrive%) Else (set newDocuments=U:\)
set registryPath1="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
set registryPath2="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
>null reg add %registryPath1% /v "Personal" /t REG_SZ /d %newDocuments% /f
>null reg add %registryPath2% /v "Personal" /t REG_EXPAND_SZ /d %newDocuments% /f
>null reg add %registryPath2% /v "{F42EE2D3-909F-4907-8871-4C22FC0BF756}" /t REG_EXPAND_SZ /d %newDocuments% /f
echo Redirection completed.
%echo%
Pause
%echo%
使用'IF存在'%udrive%\“(GOTO:FolderRedirect)ELSE GOTO:FolderRedirect2'。阅读'if /?'获取基本解释。 – JosefZ
它仍然违反其他条件。无论目标文件夹是否仍存在其默认条件。 – LaneDutch
在':FolderRedirect2'标签之前插入'goto:somewhere'。 – JosefZ