1. @echo off
  2. cls
  3. echo       ##########################################################
  4. echo       #                                                        #
  5. echo       #                      设置磁盘权限                  
  6. echo       项:                                            #
  7. echo       #                                                        #
  8. echo       #      1 如需使用PHP请先使用“服务器自主管理工具箱”安   #
  9. echo       #        装再使用此程序设置权限,若手动安装PHP则需手动   #
  10. echo       #        给PHP目录加上USERS的读权限再使用此脚本。        #
  11. echo       #                                                        #
  12. echo       #      2 此脚本只给了网站目录IIS访问帐户的修改权限,     #
  13. echo       #        如需要使用.net需手动加上IIS_WPG组的权限。       #
  14. echo       #                                                        #
  15. echo       #      3 此脚本只适用于网站服务。                        #
  16. echo       #                                                        #
  17. echo       #      4 添加修改权限方法:右键目录叵文件--属性--安全    #
  18. echo       #        选择用户,在下方法勾上需要的权限。点击添加--    #
  19. echo       #        高级--立即查找,选择用户名确定即可添加用户      #
  20. echo       #                                                        #
  21. echo       ##########################################################
  22. echo.
  23. rem ====================================得到IUSER帐户
  24. net user|find /v "命令成功完成"> %windir%\temp\isUser1.txt 2>nul
  25. echo.> %windir%\temp\isUser.txt 2>nul
  26. set webUser=
  27. for /f "skip=4 tokens=1" %%i in (%windir%\temp\isUser1.txt) do echo %%i>> %windir%\temp\isUser.txt 2>nul
  28. for /f "skip=4 tokens=2" %%i in (%windir%\temp\isUser1.txt) do echo %%i>> %windir%\temp\isUser.txt 2>nul
  29. for /f "skip=4 tokens=3" %%i in (%windir%\temp\isUser1.txt) do echo %%i>> %windir%\temp\isUser.txt 2>nul
  30. for /f "skip=1" %%i in (%windir%\temp\isUser.txt) do call:GetIusr %%i
  31. set /p webUser=输入网站访问帐号(为空则使用默认帐号[%webUser%]):
  32. del /f /q %windir%\temp\isUser1.txt
  33. del /f /q %windir%\temp\isUser.txt
  34. goto endGetIusr
  35. :GetIusr
  36. set webUser1=%1
  37. if /i %webUser1:~0,5%==IUSR_  set webUser=%1
  38. goto :eof
  39. :endGetIusr
  40. REM ===============================获取C盘文件列表
  41. set /a No=0
  42. set /a No1=0
  43. set /p=初始化程序... <nul
  44. set 退格=
  45. echo y|cacls c:\ /g administrators:f > nul 2>nul
  46. cacls c:\ /g system:f /e > nul 2>nul
  47. dir /s /b c:\ > %windir%\temp\cacls.txt 2>nul
  48. dir /s /b %windir%\ > %windir%\temp\cacls1.txt 2>nul
  49. for /f "tokens=1,2 delims=:" %%a in ('findstr /n ".*" "%windir%\temp\cacls.txt"') do set /a totalNo=%%a
  50. for /f "tokens=1,2 delims=:" %%a in ('findstr /n ".*" "%windir%\temp\cacls1.txt"') do set /a totalNo1=%%a+13
  51. set /p=ok < nul
  52. echo.
  53. REM ===============================开始设置C盘权限
  54. set isGoOn=Y
  55. set /p isGoOn=是否设置C盘权限(Y/N)[Y]:
  56. if /i "%isGoOn%"=="N" goto endSetC
  57. set /p=初始化C盘权限... 0/%totalNo%<nul
  58. for /f "tokens=* delims=" %%i in (%windir%\temp\cacls.txt) do call:setAcl "%%i"
  59. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  60. set /p=初始化C盘权限... OK                               <nul
  61. echo.
  62. set /p=设置C盘权限细节... 0/%totalNo1%<nul
  63. for /f "tokens=* delims=" %%i in (%windir%\temp\cacls1.txt) do call:addUsers "%%i"
  64. cacls "%windir%" /t /g Users:r /e /c > nul 2> nul
  65. set /a No1+=1
  66. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  67. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  68. cacls "C:\Program Files\Common Files\ODBC" /g Users:r /e /c > nul 2> nul
  69. set /a No1+=1
  70. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  71. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  72. cacls "C:\Program Files\Common Files\Services" /g Users:r /e /c > nul 2> nul
  73. set /a No1+=1
  74. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  75. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  76. cacls "C:\Program Files\Common Files\System" /g Users:r /e /c > nul 2> nul
  77. set /a No1+=1
  78. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  79. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  80. cacls "C:\Program Files (x86)\Common Files\ODBC" /g Users:r /e /c > nul 2> nul
  81. set /a No1+=1
  82. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  83. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  84. cacls "C:\Program Files (x86)\Common Files\Services" /g Users:r /e /c > nul 2> nul
  85. set /a No1+=1
  86. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  87. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  88. cacls "C:\Program Files (x86)\Common Files\System" /g Users:r /e /c > nul 2> nul
  89. set /a No1+=1
  90. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  91. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  92. cacls "%windir%\temp" /g Users:c /e /c > nul 2> nul
  93. set /a No1+=1
  94. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  95. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  96. cacls "%windir%\System32\cmd.exe" /r Users /e /c > nul 2> nul
  97. set /a No1+=1
  98. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  99. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  100. cacls "%windir%\System32\cacls.exe" /r Users /e /c > nul 2> nul
  101. set /a No1+=1
  102. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  103. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  104. cacls "%windir%\System32\net.exe" /r Users /e /c > nul 2> nul
  105. set /a No1+=1
  106. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  107. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  108. cacls "%windir%\System32\regsvr32.exe" /r Users /e /c > nul 2> nul
  109. set /a No1+=1
  110. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  111. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  112. cacls "c:\php5" /r Users /e /c > nul 2> nul
  113. set /a No1+=1
  114. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  115. set /p=设置C盘权限细节... OK                                 <nul
  116. echo.
  117. goto endSetC
  118. :setAcl
  119. set /a No+=1
  120. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  121. set /p=初始化C盘权限... %No%/%totalNo%<nul
  122. set tmpPath=%1
  123. echo y|cacls %1 /g administrators:f > nul 2>nul
  124. cacls %1 /g system:f /e > nul 2>nul
  125. goto :eof
  126. :addUsers
  127. set /a No1+=1
  128. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  129. set /p=设置C盘权限细节... %No1%/%totalNo1%<nul
  130. cacls %1 /g Users:r /e > nul 2>nul
  131. goto :eof
  132. :endSetC
  133. REM ========================设置其它盘权限
  134. set DiskStr=DEFGHIJKLMNOPQRSTUVWXYZ
  135. set /a DiskNo=23
  136. :GoOnSetDisk
  137. set thisDisk=%DiskStr:~0,1%
  138. set DiskStr=%DiskStr:~1%
  139. set /a DiskNo-=1
  140. set isGoOn=Y
  141. set /p isGoOn=是否设置%thisDisk%盘权限(Y/N)[Y]:
  142. if /i "%isGoOn%"=="N" goto SetOtherDisk
  143. set /p=设置%thisDisk%盘权限... <nul
  144. dir /s /b %thisDisk%:\ > %windir%\temp\cacls.txt 2> nul
  145. set /a totalNo=0
  146. set /a No=0
  147. for /f "tokens=1,2 delims=:" %%a in ('findstr /n ".*" "%windir%\temp\cacls.txt"') do set /a totalNo=%%a+1
  148. for /f "tokens=* delims=" %%i in (%windir%\temp\cacls.txt) do call:setDisk "%%i"
  149. echo y|cacls %thisDisk%:\ /g administrators:f > nul 2>nul
  150. cacls %thisDisk%:\ /g system:f /e > nul 2>nul
  151. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  152. set /p=设置%thisDisk%盘权限... OK                              <nul
  153. echo.
  154. if %DiskNo% GTR 0 goto GoOnSetDisk
  155. goto endSetDisk
  156. :SetOtherDisk
  157. set isSetOther=Y
  158. set /p isSetOther=是否设置其它盘权限(Y/N)[Y]:
  159. if /i "%isSetOther%"=="N" goto endSetDisk
  160. goto :GoOnSetDisk
  161. :setDisk
  162. set /a No+=1
  163. echo y|cacls %1 /g administrators:f > nul 2>nul
  164. cacls %1 /g system:f /e > nul 2>nul
  165. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  166. set /p=设置%thisDisk%盘权限... %No%/%totalNo%<nul
  167. goto :eof
  168. :endSetDisk
  169. REM =======================设置网站目录权限
  170. tony.rings> %windir%\temp\webDir.txt 2>nul
  171. : addWebDir
  172. set WebDir=
  173. set /p WebDir=添加网站目录(为空则添加结束):
  174. if "%WebDir%"=="" goto endAddWebDir
  175. echo %WebDir%>> %windir%\temp\webDir.txt 2>nul
  176. goto addWebDir
  177. :endAddWebDir
  178. for /f "tokens=* delims=" %%i in (%windir%\temp\webDir.txt) do call:setWebDir "%%i"
  179. goto endSetWebDir
  180. :setWebDir
  181. set /a No=1
  182. set /a totalNo=1
  183. set /p=设置%1权限... <nul
  184. dir /s /b %1> %windir%\temp\webSubDir.txt 2>nul
  185. for /f "tokens=1,2 delims=:" %%a in ('findstr /n ".*" "%windir%\temp\webSubDir.txt"') do set /a totalNo=%%a+1
  186. cacls %1 /t /g %webUser%:c /e /c > nul 2> nul
  187. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  188. set /p=设置%1权限... 1/%totalNo% <nul
  189. for /f "tokens=* delims=" %%i in (%windir%\temp\webSubDir.txt) do call:setWebSubDir "%%i" %1
  190. goto :eof
  191. :setWebSubDir
  192. set /a No+=1
  193. cacls %1 /t /g %webUser%:c /e /c > nul 2> nul
  194. set /p=%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格%%退格 %%退格%%退格%%退格%%退格%%退格%<nul
  195. set /p=设置%2权限... %No%/%totalNo% <nul
  196. goto :eof
  197. :endSetWebDir
  198. del /f /q %windir%\temp\cacls1.txt
  199. del /f /q %windir%\temp\cacls.txt
  200. del /f /q %windir%\temp\webDir.txt
  201. del /f /q %windir%\temp\webSubDir.txt
  202. echo .
  203. echo 恭喜您,设置完成! 请按任意键退出程序!
  204. pause > nul