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